<!DOCTYPE html>
<html lang="en" dir="ltr">

<head prefix="og: http://ogp.me/ns#">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>CS229 Machine Learning——Andrew Ng——Stanford – ruokeqx&#39;s blog</title>
    


  
  <script defer src="/js/fuse.min.8dfbf8696f107ab8b55732efbb04c5c51576692a4a2cce6effef9f6e92d341a7.js"></script>



<script src="/js/enquire.min.aa37bdcb743826eecdae5c5d177fc7d6552340f1b4378ffaa9c82b2c6111400b.js"></script>

<script defer src="/js/lazysizes.min.498676c34eb225e85357ab0ce19c3c1244f3bd0bf595e5684d1b9d50ea4fbc42.js"></script>

<script defer src="/js/helper/getParents.min.b75dda22e2d1c0e1e0574c7764bb95bec70c0fb0d4d5440339ba68c685d5a661.js"></script>

<script defer src="/js/helper/fadeinout.min.b1a8c6db3f3cc261756044570d21596f0f083625d41433dc9ac02aba5e53777b.js"></script>

<script defer src="/js/helper/closest.min.js"></script>
  
<script>
  "use strict";

  
  
  if (window.NodeList && !NodeList.prototype.forEach) {
    NodeList.prototype.forEach = Array.prototype.forEach;
  }

  
  if (!String.prototype.includes) {
    String.prototype.includes = function (search, start) {
      'use strict';

      if (search instanceof RegExp) {
        throw TypeError('first argument must not be a RegExp');
      }
      if (start === undefined) { start = 0; }
      return this.indexOf(search, start) !== -1;
    };
  }

  
  Document.prototype.append = Element.prototype.append = function append() {
    this.appendChild(_mutation(arguments));
  };
  function _mutation(nodes) {
    if (!nodes.length) {
      throw new Error('DOM Exception 8');
    } else if (nodes.length === 1) {
      return typeof nodes[0] === 'string' ? document.createTextNode(nodes[0]) : nodes[0];
    } else {
      var
      fragment = document.createDocumentFragment(),
      length = nodes.length,
      index = -1,
      node;

      while (++index < length) {
        node = nodes[index];

        fragment.appendChild(typeof node === 'string' ? document.createTextNode(node) : node);
      }

      return fragment;
    }
  }

  
  if (!String.prototype.startsWith) {
    String.prototype.startsWith = function (searchString, position) {
      position = position || 0;
      return this.indexOf(searchString, position) === position;
    };
  }
  


  document.addEventListener('DOMContentLoaded', function () {
    
    var navCollapseBtn = document.querySelector('.navbar__burger');
    navCollapseBtn ? navCollapseBtn.addEventListener('click', function (e) {
      var navCollapse = document.querySelector('.navbarm__collapse');

      if (navCollapse) {
        var dataOpen = navCollapse.getAttribute('data-open');

        if (dataOpen === 'true') {
          navCollapse.setAttribute('data-open', 'false');
          navCollapse.style.maxHeight = 0;
          navCollapseBtn.classList.remove('is-active');
        } else {
          navCollapse.setAttribute('data-open', 'true');
          navCollapse.style.maxHeight = navCollapse.scrollHeight + "px";
          navCollapseBtn.classList.add('is-active');
        }
      }
    }) : null;
    


    
    var tables = document.querySelectorAll('.single__contents > table');
    for (let i = 0; i < tables.length; i++) {
      var table = tables[i];
      var wrapper = document.createElement('div');
      wrapper.className = 'table-wrapper';
      table.parentElement.replaceChild(wrapper, table);
      wrapper.appendChild(table);
    }
    


    
    var footNoteRefs = document.querySelectorAll('.footnote-ref');
    var footNoteBackRefs = document.querySelectorAll('.footnote-backref');

    footNoteRefs ? 
    footNoteRefs.forEach(function(elem, idx) {
      elem.onmouseenter = function () {
        if (navbar.classList.contains('scrolling')) {
          navbar.classList.remove('scrolling');
        }
      }

      elem.onmouseleave = function () {
        if (!navbar.classList.contains('scrolling')) {
          setTimeout(function () {
            navbar.classList.add('scrolling');
          }, 100);
        }
      }

      elem.onclick = function () {
        if (!navbar.classList.contains('scrolling')) {
          navbar.classList.remove('navbar--show');
          navbar.classList.remove('navbar--hide');
          navbar.classList.add('navbar--hide');
        }
      }
    }) : null;

    footNoteBackRefs ? 
    footNoteBackRefs.forEach(function(elem, idx) {
      elem.onmouseenter = function () {
        if (navbar.classList.contains('scrolling')) {
          navbar.classList.remove('scrolling');
        }
      }

      elem.onmouseleave = function () {
        if (!navbar.classList.contains('scrolling')) {
          setTimeout(function() {
            navbar.classList.add('scrolling');
          }, 100);
        }
      }

      elem.onclick = function () {
        if (!navbar.classList.contains('scrolling')) {
          navbar.classList.remove('navbar--show');
          navbar.classList.remove('navbar--hide');
          navbar.classList.add('navbar--hide');
        }
      }
    }) : null;
    


    
    var summaryContainer = document.querySelector('.summary__container');
    var searchResult = document.querySelector('.search-result');
    var searchResultCloseBtn = document.querySelector('.search-result__close');
    searchResultCloseBtn ? searchResultCloseBtn.addEventListener('click', function (e) {
      searchResult.setAttribute('data-display', 'none');
      summaryContainer.setAttribute('data-display', 'block');
    }) : null;
    


    
    document.querySelectorAll('.tab') ? 
    document.querySelectorAll('.tab').forEach(function(elem, idx) {
      var containerId = elem.getAttribute('id');
      var containerElem = elem;
      var tabLinks = elem.querySelectorAll('.tab__link');
      var tabContents = elem.querySelectorAll('.tab__content');
      var ids = [];

      tabLinks && tabLinks.length > 0 ?
      tabLinks.forEach(function(link, index, self) {
        link.onclick = function(e) {
          for (var i = 0; i < self.length; i++) {
            if (index === parseInt(i, 10)) {
              if (!self[i].classList.contains('active')) {
                self[i].classList.add('active');
                tabContents[i].style.display = 'block';
              }
            } else {
              self[i].classList.remove('active');
              tabContents[i].style.display = 'none';
            }
          }
        }
      }) : null;
    }) : null;
    


    
    document.querySelectorAll('.codetab') ? 
    document.querySelectorAll('.codetab').forEach(function(elem, idx) {
      var containerId = elem.getAttribute('id');
      var containerElem = elem;
      var codetabLinks = elem.querySelectorAll('.codetab__link');
      var codetabContents = elem.querySelectorAll('.codetab__content');
      var ids = [];

      codetabLinks && codetabLinks.length > 0 ?
      codetabLinks.forEach(function(link, index, self) {
        link.onclick = function(e) {
          for (var i = 0; i < self.length; i++) {
            if (index === parseInt(i, 10)) {
              if (!self[i].classList.contains('active')) {
                self[i].classList.add('active');
                codetabContents[i].style.display = 'block';
              }
            } else {
              self[i].classList.remove('active');
              codetabContents[i].style.display = 'none';
            }
          }
        }
      }) : null;
    }) : null;
    


    
    var gttBtn = document.getElementById("gtt");
    gttBtn.style.display = "none";
    gttBtn.addEventListener('click', function () {
      if (window.document.documentMode) {
        document.documentElement.scrollTop = 0;
      } else {
        scrollToTop(250);
      }
    });

    function scrollToTop(scrollDuration) {
      var scrollStep = -window.scrollY / (scrollDuration / 15);
      var scrollInterval = setInterval(function () {
        if (window.scrollY != 0) {
          window.scrollBy(0, scrollStep);
        }
        else clearInterval(scrollInterval);
      }, 15);
    }

    var scrollFunction = function () {
      if (document.body.scrollTop > 250 || document.documentElement.scrollTop > 250) {
        gttBtn.style.display = "block";
      } else {
        gttBtn.style.display = "none";
      }
    }
    


    
    var expandBtn = document.querySelectorAll('.expand__button');

    for (let i = 0; i < expandBtn.length; i++) {
      expandBtn[i].addEventListener("click", function () {
        var content = this.nextElementSibling;
        if (content.style.maxHeight) {
          content.style.maxHeight = null;
          this.querySelector('svg').classList.add('expand-icon__right');
          this.querySelector('svg').classList.remove('expand-icon__down');
        } else {
          content.style.maxHeight = content.scrollHeight + "px";
          this.querySelector('svg').classList.remove('expand-icon__right');
          this.querySelector('svg').classList.add('expand-icon__down');
        }
      });
    }
    


    
    var lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
    var tocElem = document.querySelector('.toc');
    var tableOfContentsElem = tocElem ? tocElem.querySelector('#TableOfContents') : null;
    var toggleTocElem = document.getElementById('toggle-toc');
    var singleContentsElem = document.querySelector('.single__contents');
    var navbar = document.querySelector('.navbar');
    var tocFlexbox = document.querySelector('.toc__flexbox');
    var tocFlexboxOuter = document.querySelector('.toc__flexbox--outer');
    var expandContents = document.querySelectorAll('.expand__content');
    var boxContents = document.querySelectorAll('.box');
    var notAllowedTitleIds = null;

    
    var tocFolding = JSON.parse("true");
    
    var tocLevels = JSON.parse("[\"h2\",\"h3\",\"h4\",\"h5\"]");
    
    if (tocLevels) {
      tocLevels = tocLevels.toString();
    } else {
      tocLevels = "h1, h2, h3, h4, h5, h6";
    }

    
    singleContentsElem && singleContentsElem.querySelectorAll(".tab") ?
    singleContentsElem.querySelectorAll(".tab").forEach(function (elem) {
      elem.querySelectorAll(tocLevels).forEach(function (element) {
        notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
          notAllowedTitleIds.concat(element.getAttribute('id')) :
          [element.getAttribute('id')];
      });
    }) : null;

    
    expandContents ? expandContents.forEach(function(elem) {
      elem.querySelectorAll(tocLevels).forEach(function (element) {
        notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
          notAllowedTitleIds.concat(element.getAttribute('id')) :
          [element.getAttribute('id')];
      });
    }) : null;

    
    boxContents ? boxContents.forEach(function(elem) {
      elem.querySelectorAll(tocLevels).forEach(function (element) {
        notAllowedTitleIds = Array.isArray(notAllowedTitleIds) ?
          notAllowedTitleIds.concat(element.getAttribute('id')) :
          [element.getAttribute('id')];
      });
    }) : null;

    
    window.onscroll = function () {
      scrollFunction();
      
      var st = window.pageYOffset || document.documentElement.scrollTop;
      if (st > lastScrollTop) { 
        if (st < 250) {
          gttBtn.style.display = "none";
        } else {
          gttBtn.style.display = "block";
        }

        if (st < 45) {
          return null;
        }

        if (navbar.classList.contains('scrolling')) {
          if (!navbar.classList.contains('navbar--hide')) {
            navbar.classList.add('navbar--hide');
          } else if (navbar.classList.contains('navbar--show')) {
            navbar.classList.remove('navbar--show');
          }
        }

        if (singleContentsElem) {
          if (singleContentsElem.querySelectorAll(tocLevels).length > 0) {
            singleContentsElem.querySelectorAll(tocLevels).forEach(function (elem) {
              if (toggleTocElem && !toggleTocElem.checked) {
                return null;
              }

              if (notAllowedTitleIds && notAllowedTitleIds.includes(elem.getAttribute('id'))) {
                return null;
              }
              
              if (document.documentElement.scrollTop >= elem.offsetTop) {
                if (tableOfContentsElem) {
                  var id = elem.getAttribute('id');
                  tocElem.querySelectorAll('a').forEach(function (elem) {
                    elem.classList.remove('active');
                  });
                  tocElem.querySelector('a[href="#' + id + '"]') ?
                    tocElem.querySelector('a[href="#' + id + '"]').classList.add('active') : null;

                  if (false === tocFolding) {
                    
                  } else {
                    tableOfContentsElem.querySelectorAll('ul') ?
                      tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) {
                        rootUl.querySelectorAll('li').forEach(function (liElem) {
                          liElem.querySelectorAll('ul').forEach(function (ulElem) {
                            ulElem.style.display = 'none';
                          });
                        });
                      }) : null;
                  }

                  var curElem = tableOfContentsElem.querySelector("[href='#" + id + "']");
                  if (curElem && curElem.nextElementSibling) {
                    curElem.nextElementSibling.style.display = 'block';
                  }
                  getParents(curElem, 'ul') ?
                    getParents(curElem, 'ul').forEach(function (elem) {
                      elem.style.display = 'block';
                    }) : null;
                }
              }
            });
          } else {
            if (tocFlexbox) {
              tocFlexbox.setAttribute('data-position', '');
              if (!tocFlexbox.classList.contains('hide')) {
                tocFlexbox.classList.add('hide');
              }
            }
            if (tocFlexboxOuter) {
              tocFlexboxOuter.setAttribute('data-position', '');
              if (!tocFlexboxOuter.classList.contains('hide')) {
                tocFlexboxOuter.classList.add('hide');
              }
            }
          }
        }
      } else { 
        if (st < 250) {
          gttBtn.style.display = "none";
        }

        if (navbar.classList.contains('scrolling')) {
          if (navbar.classList.contains('navbar--hide')) {
            navbar.classList.remove('navbar--hide');
          } else if (!navbar.classList.contains('navbar--show')) {
            navbar.classList.add('navbar--show');
          }
        }

        if (singleContentsElem) {
          if (singleContentsElem.querySelectorAll(tocLevels).length > 0) {
            singleContentsElem.querySelectorAll(tocLevels).forEach(function (elem) {
              if (toggleTocElem && !toggleTocElem.checked) {
                return null;
              }
              
              if (notAllowedTitleIds && notAllowedTitleIds.includes(elem.getAttribute('id'))) {
                return null;
              }

              if (document.documentElement.scrollTop >= elem.offsetTop) {
                if (tableOfContentsElem) {
                  var id = elem.getAttribute('id');
                  tocElem.querySelectorAll('a').forEach(function (elem) {
                    elem.classList.remove('active');
                  });
                  tocElem.querySelector('a[href="#' + id + '"]') ?
                    tocElem.querySelector('a[href="#' + id + '"]').classList.add('active') : null;

                  if (false === tocFolding) {
                    
                  } else {
                    tableOfContentsElem.querySelectorAll('ul') ?
                      tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) {
                        rootUl.querySelectorAll('li').forEach(function (liElem) {
                          liElem.querySelectorAll('ul').forEach(function (ulElem) {
                            ulElem.style.display = 'none';
                          });
                        });
                      }) : null;
                  }

                  var curElem = tableOfContentsElem.querySelector("[href='#" + id + "']");
                  if (curElem && curElem.nextElementSibling) {
                    curElem.nextElementSibling.style.display = 'block';
                  }
                  getParents(curElem, 'ul') ?
                    getParents(curElem, 'ul').forEach(function (elem) {
                      elem.style.display = 'block';
                    }) : null;
                }
              }
            });
          } else {
            if (tocFlexbox && !tocFlexbox.classList.contains('hide')) {
              tocFlexbox.classList.add('hide');
            }
            if (tocFlexboxOuter && !tocFlexboxOuter.classList.contains('hide')) {
              tocFlexboxOuter.classList.add('hide');
            }
          }
          
        }

        if (tableOfContentsElem && document.documentElement.scrollTop < 250) {
          if (false === tocFolding) {

          } else {
            tableOfContentsElem.querySelector('ul') ?
              tableOfContentsElem.querySelector('ul').querySelectorAll('li').forEach(function (liElem) {
                liElem.querySelectorAll('ul').forEach(function (ulElem) {
                  ulElem.style.display = 'none';
                });
              }) : null;
          }
        }
      }
      lastScrollTop = st <= 0 ? 0 : st;
    };
  


  
    var localTheme = localStorage.getItem('theme');
    var rootEleme = document.getElementById('root');
    var selectThemeElem = document.querySelectorAll('.select-theme');
    var selectThemeItemElem = document.querySelectorAll('.select-theme__item');
    
    
    var skinDarkCode = JSON.parse("\"dark\"");
    
    var skinLightCode = JSON.parse("\"light\"");
    
    var skinHackerCode = JSON.parse("\"hacker\"");
    
    var skinSolarizedCode = JSON.parse("\"solarized\"");
    
    var skinKimbieCode = JSON.parse("\"kimbie\"");

    var setMetaColor = function(themeColor) {
      var metaMsapplicationTileColor = document.getElementsByName('msapplication-TileColor')[0];
      var metaThemeColor = document.getElementsByName('theme-color')[0];
      var metaMsapplicationNavbuttonColor = document.getElementsByName('msapplication-navbutton-color')[0];
      var metaAppleMobileWebAappStatusBarStyle = document.getElementsByName('apple-mobile-web-app-status-bar-style')[0];

      if (themeColor.includes('dark')) {
        metaMsapplicationTileColor.setAttribute('content', '#fcfcfa');
        metaThemeColor.setAttribute('content', '#403E41');
        metaMsapplicationNavbuttonColor.setAttribute('content', '#403E41');
        metaAppleMobileWebAappStatusBarStyle.setAttribute('content', '#403E41');
      } else if (themeColor.includes('light')) {
        metaMsapplicationTileColor.setAttribute('content', '#555');
        metaThemeColor.setAttribute('content', '#eee');
        metaMsapplicationNavbuttonColor.setAttribute('content', '#eee');
        metaAppleMobileWebAappStatusBarStyle.setAttribute('content', '#eee');
      } else if (themeColor.includes('hacker')) {
        metaMsapplicationTileColor.setAttribute('content', '#e3cd26');
        metaThemeColor.setAttribute('content', '#252526');
        metaMsapplicationNavbuttonColor.setAttribute('content', '#252526');
        metaAppleMobileWebAappStatusBarStyle.setAttribute('content', '#252526');
      } else if (themeColor.includes('solarized')) {
        metaMsapplicationTileColor.setAttribute('content', '#d3af86');
        metaThemeColor.setAttribute('content', '#51412c');
        metaMsapplicationNavbuttonColor.setAttribute('content', '#51412c');
        metaAppleMobileWebAappStatusBarStyle.setAttribute('content', '#51412c');
      } else if (themeColor.includes('kimbie')) {
        metaMsapplicationTileColor.setAttribute('content', '#586e75');
        metaThemeColor.setAttribute('content', '#eee8d5');
        metaMsapplicationNavbuttonColor.setAttribute('content', '#eee8d5');
        metaAppleMobileWebAappStatusBarStyle.setAttribute('content', '#eee8d5');
      }
    }

    var parseSkinCode = function(themeText) {
      if (themeText === skinDarkCode) {
        return 'dark';
      } else if (themeText === skinLightCode) {
        return 'light';
      } else if (themeText === skinHackerCode) {
        return 'hacker';
      } else if (themeText === skinSolarizedCode) {
        return 'solarized';
      } else if (themeText === skinKimbieCode) {
        return 'kimbie';
      }
    }
    
    if (localTheme) {
      selectThemeItemElem ? 
      selectThemeItemElem.forEach(function (elem) {
        if (elem.text.trim() === localTheme) {
          elem.classList.add('is-active');
        } else {
          elem.classList.remove('is-active');
        }
      }) : null;

      setMetaColor(localTheme);
    } else {
      setMetaColor(rootEleme.className);
    }

    selectThemeItemElem ? 
    selectThemeItemElem.forEach(function (v, i) {
      v.addEventListener('click', function (e) {
        var selectedThemeVariant = parseSkinCode(e.target.text.trim());
        localStorage.setItem('theme', selectedThemeVariant);
        setMetaColor(selectedThemeVariant);

        rootEleme.removeAttribute('class');
        rootEleme.classList.add('theme__' + selectedThemeVariant);
        selectThemeElem.forEach(function(rootElem) {
          rootElem.querySelectorAll('a').forEach(function (elem) {
            if (elem.classList) {
              if (elem.text.trim() === selectedThemeVariant) {
                if (!elem.classList.contains('is-active')) {
                  elem.classList.add('is-active');
                }
              } else {
                if (elem.classList.contains('is-active')) {
                  elem.classList.remove('is-active');
                }
              }
            }
          });
        });

        if (window.mermaid) {
          if (selectedThemeVariant === "dark" || selectedThemeVariant === "hacker") {
            mermaid.initialize({ theme: 'dark' });
            location.reload();
          } else {
            mermaid.initialize({ theme: 'default' });
            location.reload();
          }
        }

        var utterances = document.getElementById('utterances');
        if (utterances) {
          utterances.querySelector('iframe').contentWindow.postMessage({
            type: 'set-theme',
            theme: selectedThemeVariant === "dark" || selectedThemeVariant === "hacker" ? 'photon-dark' : selectedThemeVariant === 'kimbie' ? 'github-dark-orange' : 'github-light',
          }, 'https://utteranc.es');
        }

        var twitterCards = document.querySelectorAll('.twitter-timeline');
        if (twitterCards) {
          window.postMessage({
            type: 'set-twitter-theme',
            theme: selectedThemeVariant === 'light' || selectedThemeVariant === 'solarized' ? 'light' : 'dark',
          });
        }
      });
    }) : null;
  


  
    
    var baseurl = JSON.parse("\"https://ruokeqx.gitee.io\"");
    
    var permalink = JSON.parse("\"https://ruokeqx.gitee.io/posts/machine-learning-andrew-ng-stanford/\"");
    
    var langprefix = JSON.parse("\"\"");
    var searchResults = null;
    var searchMenu = null;
    var searchText = null;
    
    
    var enableSearch = JSON.parse("true");
    
    var searchDistance = JSON.parse("100");
    
    var searchThreshold = JSON.parse("0.4");
    
    var searchContent = JSON.parse("true");
    
    var enableSearchHighlight = JSON.parse("true");
    
    var searchResultPosition = JSON.parse("\"main\"");
    
    var sectionType = JSON.parse("\"posts\"");
    
    var kind = JSON.parse("\"page\"");
    
    var fuse = null;

    if (enableSearch) {
      (function initFuse() {
        var xhr = new XMLHttpRequest();
        if (sectionType === "publication" && kind !== "page") {
          xhr.open('GET', permalink + "index.json");
        } else {
          xhr.open('GET', baseurl + langprefix + "/index.json");
        }
        
        xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
        xhr.onload = function () {
          if (xhr.status === 200) {
            fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), {
              keys: sectionType.includes('publication') ? ['title', 'abstract'] : 
                searchContent ? ['title', 'description', 'content'] : ['title', 'description'],
              includeMatches: enableSearchHighlight,
              shouldSort: true, 
              threshold: searchThreshold ? searchThreshold : 0.4, 
              location: 0, 
              distance: searchDistance ? searchDistance : 100, 
              maxPatternLength: 32,
              minMatchCharLength: 1,
              isCaseSensitive: false, 
              findAllMatches: false, 
              useExtendedSearch: false, 
            });
            window.fuse = fuse;
          }
          else {
            console.error('[' + xhr.status + ']Error:', xhr.statusText);
          }
        };
        xhr.send();
      })();
    }

    function makeLi(ulElem, obj) {
      var li = document.createElement('li');
      li.className = 'search-result__item';
      
      var a = document.createElement('a');
      a.innerHTML = obj.item.title;
      a.setAttribute('class', 'search-result__item--title');
      a.setAttribute('href', obj.item.uri);

      var descDiv = document.createElement('div');
      descDiv.setAttribute('class', 'search-result__item--desc');
      if (obj.item.description) {
        descDiv.innerHTML = obj.item.description;
      } else if (obj.item.content) {
        descDiv.innerHTML = obj.item.content.substring(0, 225);
      }
      
      li.appendChild(a);
      li.appendChild(descDiv);
      ulElem.appendChild(li);
    }

    function makeHighlightLi(ulElem, obj) {
      var li = document.createElement('li');
      li.className = 'search-result__item';
      var descDiv = null;

      var a = document.createElement('a');
      a.innerHTML = obj.item.title;
      a.setAttribute('class', 'search-result__item--title');
      a.setAttribute('href', obj.item.uri);

      if (obj.matches && obj.matches.length) {
        for (var i = 0; i < obj.matches.length; i++) {
          if ('title' === obj.matches[i].key) {
            a = document.createElement('a');
            a.innerHTML = generateHighlightedText(obj.matches[i].value, obj.matches[i].indices);
            a.setAttribute('class', 'search-result__item--title');
            a.setAttribute('href', obj.item.uri);
          }
          
          if ('description' === obj.matches[i].key) {
            descDiv = document.createElement('div');
            descDiv.setAttribute('class', 'search-result__item--desc');
            descDiv.innerHTML = generateHighlightedText(obj.item.description, obj.matches[i].indices);
          } else if ('content' === obj.matches[i].key) {
            if (!descDiv) {
              descDiv = document.createElement('div');
              descDiv.setAttribute('class', 'search-result__item--desc');
              descDiv.innerHTML = generateHighlightedText(obj.item.content.substring(0, 150), obj.matches[i].indices);
            }
          } else {
            if (obj.item.description) {
              descDiv = document.createElement('div');
              descDiv.setAttribute('class', 'search-result__item--desc');
              descDiv.innerHTML = obj.item.description;
            } else {
              descDiv = document.createElement('div');
              descDiv.setAttribute('class', 'search-result__item--desc');
              descDiv.innerHTML = obj.item.content.substring(0, 150);
            }
          }
        }

        li.appendChild(a);
        if (descDiv) {
          li.appendChild(descDiv);
        }
        if (li) {
          ulElem.appendChild(li);
        }
      }
    }

    function renderSearchResultsSide(searchText, results) {
      searchResults = document.getElementById('search-results');
      searchMenu = document.getElementById('search-menu');
      searchResults.setAttribute('class', 'dropdown is-active');
      
      var ul = document.createElement('ul');
      ul.setAttribute('class', 'dropdown-content search-content');

      if (results.length) {
        results.forEach(function (result) {
          var li = document.createElement('li');
          var a = document.createElement('a');
          a.setAttribute('href', result.uri);
          a.setAttribute('class', 'dropdown-item');
          a.appendChild(li);

          var titleDiv = document.createElement('div');
          titleDiv.innerHTML = result.title;
          titleDiv.setAttribute('class', 'menu-item__title');

          var descDiv = document.createElement('div');
          descDiv.setAttribute('class', 'menu-item__desc');
          if (result.description) {
            descDiv.innerHTML = result.description;
          } else if (result.content) {
            descDiv.innerHTML = result.content.substring(0, 150);
          }

          li.appendChild(titleDiv);
          li.appendChild(descDiv);
          ul.appendChild(a);
        });
      } else {
        var li = document.createElement('li');
        li.setAttribute('class', 'dropdown-item');
        li.innerText = 'No results found';
        ul.appendChild(li);
      }

      while (searchMenu.hasChildNodes()) {
        searchMenu.removeChild(
          searchMenu.lastChild
        );
      }
      
      searchMenu.appendChild(ul);
    }

    function renderSearchHighlightResultsSide(searchText, results) {
      searchResults = document.getElementById('search-results');
      searchMenu = document.getElementById('search-menu');
      searchResults.setAttribute('class', 'dropdown is-active');

      var ul = document.createElement('ul');
      ul.setAttribute('class', 'dropdown-content search-content');

      if (results.length) {
        results.forEach(function (result) {
          var li = document.createElement('li');
          var a = document.createElement('a');
          var descDiv = null;

          a.setAttribute('href', result.item.uri);
          a.setAttribute('class', 'dropdown-item');
          a.appendChild(li);

          var titleDiv = document.createElement('div');
          titleDiv.innerHTML = result.item.title;
          titleDiv.setAttribute('class', 'menu-item__title');
          
          if (result.matches && result.matches.length) {
            for (var i = 0; i < result.matches.length; i++) {
              if ('title' === result.matches[i].key) {
                titleDiv.innerHTML = generateHighlightedText(result.matches[i].value, result.matches[i].indices);
              }

              if ('description' === result.matches[i].key) {
                descDiv = document.createElement('div');
                descDiv.setAttribute('class', 'menu-item__desc');
                descDiv.innerHTML = generateHighlightedText(result.item.description, result.matches[i].indices);
              } else if ('content' === result.matches[i].key) {
                if (!descDiv) {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'menu-item__desc');
                  descDiv.innerHTML = generateHighlightedText(result.item.content.substring(0, 150), result.matches[i].indices);
                }
              } else {
                if (result.item.description) {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'menu-item__desc');
                  descDiv.innerHTML = result.item.description;
                } else {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'menu-item__desc');
                  descDiv.innerHTML = result.item.content.substring(0, 150);
                }
              }
            }
            
            li.appendChild(titleDiv);
            if (descDiv) {
              li.appendChild(descDiv);
            }
            ul.appendChild(a);
          }
        });
      } else {
        var li = document.createElement('li');
        li.setAttribute('class', 'dropdown-item');
        li.innerText = 'No results found';
        ul.appendChild(li);
      }

      while (searchMenu.hasChildNodes()) {
        searchMenu.removeChild(
          searchMenu.lastChild
        );
      }
      searchMenu.appendChild(ul);
    }

    function renderSearchResultsMobile(searchText, results) {
      searchResults = document.getElementById('search-mobile-results');

      var content = document.createElement('div');
      content.setAttribute('class', 'mobile-search__content');

      if (results.length > 0) {
        results.forEach(function (result) {
          var item = document.createElement('a');
          item.setAttribute('href', result.uri);
          item.innerHTML = '<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ' + result.title + '</div><div class="mobile-search__item--desc">' + (result.description ? result.description : result.content) + '</div></div>';
          content.appendChild(item);
        });
      } else {
        var item = document.createElement('span');
        content.appendChild(item);
      }

      let wrap = document.getElementById('search-mobile-results');
      while (wrap.firstChild) {
        wrap.removeChild(wrap.firstChild)
      }
      searchResults.appendChild(content);      
    }

    function renderSearchHighlightResultsMobile(searchText, results) {
      searchResults = document.getElementById('search-mobile-results');

      var ul = document.createElement('div');
      ul.setAttribute('class', 'mobile-search__content');

      if (results.length) {
        results.forEach(function (result) {
          var li = document.createElement('li');
          var a = document.createElement('a');
          var descDiv = null;

          a.setAttribute('href', result.item.uri);
          a.appendChild(li);
          li.setAttribute('class', 'mobile-search__item');

          var titleDiv = document.createElement('div');
          titleDiv.innerHTML = result.item.title;
          titleDiv.setAttribute('class', 'mobile-search__item--title');
          
          if (result.matches && result.matches.length) {
            for (var i = 0; i < result.matches.length; i++) {
              if ('title' === result.matches[i].key) {
                titleDiv.innerHTML = generateHighlightedText(result.matches[i].value, result.matches[i].indices);
              }

              if ('description' === result.matches[i].key) {
                descDiv = document.createElement('div');
                descDiv.setAttribute('class', 'mobile-search__item--desc');
                descDiv.innerHTML = generateHighlightedText(result.item.description, result.matches[i].indices);
              } else if ('content' === result.matches[i].key) {
                if (!descDiv) {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'mobile-search__item--desc');
                  descDiv.innerHTML = generateHighlightedText(result.item.content.substring(0, 150), result.matches[i].indices);
                }
              } else {
                if (result.item.description) {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'mobile-search__item--desc');
                  descDiv.innerHTML = result.item.description;
                } else {
                  descDiv = document.createElement('div');
                  descDiv.setAttribute('class', 'mobile-search__item--desc');
                  descDiv.innerHTML = result.item.content.substring(0, 150);
                }
              }
            }
            
            li.appendChild(titleDiv);
            if (descDiv) {
              li.appendChild(descDiv);
            }
            ul.appendChild(a);
          }
        });
      } else {
        var item = document.createElement('span');
        ul.appendChild(item);
      }

      let wrap = document.getElementById('search-mobile-results');
      while (wrap.firstChild) {
        wrap.removeChild(wrap.firstChild)
      }
      searchResults.appendChild(ul);
    }

    function generateHighlightedText(text, regions) {
      if (!regions) {
        return text;
      }

      var content = '', nextUnhighlightedRegionStartingIndex = 0;

      regions.forEach(function(region) {
        if (region[0] === region[1]) {
          return null;
        }
        
        content += '' +
          text.substring(nextUnhighlightedRegionStartingIndex, region[0]) +
          '<span class="search__highlight">' +
            text.substring(region[0], region[1] + 1) +
          '</span>' +
        '';
        nextUnhighlightedRegionStartingIndex = region[1] + 1;
      });

      content += text.substring(nextUnhighlightedRegionStartingIndex);

      return content;
    };

    var searchElem = document.getElementById('search');
    var searchMobile = document.getElementById('search-mobile');
    var searchResultsContainer = document.getElementById('search-results');

    searchElem ?
    searchElem.addEventListener('input', function(e) {
      if (!e.target.value | window.innerWidth < 770) {
        searchResultsContainer ? searchResultsContainer.setAttribute('class', 'dropdown') : null;
        searchResult ? searchResult.setAttribute('data-display', 'none') : null;
        summaryContainer ? summaryContainer.setAttribute('data-display', 'block') : null;
        return null;
      }

      searchText = e.target.value;
      var results = fuse.search(e.target.value);
      
      if (searchResultPosition === "main") {
        if (enableSearchHighlight) {
          renderSearchHighlightResultsMain(searchText, results);
        } else {
          renderSearchResultsMain(searchText, results);
        }
      } else {
        if (enableSearchHighlight) {
          renderSearchHighlightResultsSide(searchText, results);
        } else {
          renderSearchResultsSide(searchText, results);
        }
        
        var dropdownItems = searchResultsContainer.querySelectorAll('.dropdown-item');
        dropdownItems ? dropdownItems.forEach(function(item) {
          item.addEventListener('mousedown', function(e) {
            e.target.click();
          });
        }) : null;
      }
    }) : null;

    searchElem ? 
    searchElem.addEventListener('blur', function() {
      if (window.innerWidth < 770) {
        return null;
      }
      searchResultsContainer ? searchResultsContainer.setAttribute('class', 'dropdown') : null;
    }) : null;

    searchElem ? 
    searchElem.addEventListener('click', function(e) {
      if (window.innerWidth < 770) {
        return null;
      }
      if (!e.target.value) {
        searchResultsContainer ? searchResultsContainer.setAttribute('class', 'dropdown') : null;
        return null;
      }

      searchText = e.target.value;
      var results = fuse.search(e.target.value);

      if (searchResultPosition === "main") {
        if (enableSearchHighlight) {
          renderSearchHighlightResultsMain(searchText, results);
        } else {
          renderSearchResultsMain(searchText, results);
        }
      } else{
        if (enableSearchHighlight) {
          renderSearchHighlightResultsSide(searchText, results);
        } else {
          renderSearchResultsSide(searchText, results);
        }

        var dropdownItems = searchResultsContainer.querySelectorAll('.dropdown-item');
        dropdownItems ? dropdownItems.forEach(function (item) {
          item.addEventListener('mousedown', function (e) {
            e.target.click();
          });
        }) : null;
      }
    }) : null;

    var searchMenuElem = document.getElementById("search-menu");
    var activeItem = document.querySelector('#search-menu .dropdown-item.is-active');
    var activeIndex = null;
    var items = null;
    var searchContainerMaxHeight = 350;

    searchElem ? 
    searchElem.addEventListener('keydown', function(e) {
      if (window.innerWidth < 770) {
        return null;
      }

      if (e.key === 'Escape') {
        searchResult ? searchResult.setAttribute('data-display', 'none') : null;
        summaryContainer ? summaryContainer.setAttribute('data-display', 'block') : null;
      }

      var items = document.querySelectorAll('#search-menu .dropdown-item');
      var keyCode = e.which || e.keyCode;

      if (!items || !items.length) {
        return null;
      }
      
      if (e.key === 'ArrowDown' || keyCode === 40) {
        if (activeIndex === null) {
          activeIndex = 0;
          items[activeIndex].classList.remove('is-active');
        } else {
          items[activeIndex].classList.remove('is-active');
          activeIndex = activeIndex === items.length - 1 ? 0 : activeIndex + 1;
        }
        items[activeIndex].classList.add('is-active');

        let overflowedPixel = items[activeIndex].offsetTop + items[activeIndex].clientHeight - searchContainerMaxHeight;
        if (overflowedPixel > 0) {
          document.querySelector(".search-content").scrollTop += items[activeIndex].getBoundingClientRect().height;
        } else if (activeIndex === 0) {
          document.querySelector(".search-content").scrollTop = 0;
        }
      } else if (e.key === 'ArrowUp' || keyCode === 38) {
        if (activeIndex === null) {
          activeIndex = items.length - 1;
          items[activeIndex].classList.remove('is-active');
        } else {
          items[activeIndex].classList.remove('is-active');
          activeIndex = activeIndex === 0 ? items.length - 1 : activeIndex - 1;
        }
        items[activeIndex].classList.add('is-active');
        
        let overflowedPixel = items[activeIndex].offsetTop + items[activeIndex].clientHeight - searchContainerMaxHeight;
        if (overflowedPixel < 0) {
          document.querySelector(".search-content").scrollTop -= items[activeIndex].getBoundingClientRect().height;
        } else {
          document.querySelector(".search-content").scrollTop = overflowedPixel + items[activeIndex].getBoundingClientRect().height;
        }
      } else if (e.key === 'Enter' || keyCode === 13) {
        if (items[activeIndex] && items[activeIndex].getAttribute('href')) {
          location.href = items[activeIndex].getAttribute('href');
        }
      } else if (e.key === 'Escape' || keyCode === 27) {
        e.target.value = null;
        if (searchResults) {
          searchResults.classList.remove('is-active');
        }
      }
    }) : null;

    searchMobile ? 
    searchMobile.addEventListener('input', function(e) {
      if (!e.target.value) {
        let wrap = document.getElementById('search-mobile-results');
        while (wrap.firstChild) {
          wrap.removeChild(wrap.firstChild);
        }
        return null;
      }

      searchText = e.target.value;
      var results = fuse.search(e.target.value);
      renderSearchResultsMobile(searchText, results);
      if (enableSearchHighlight) {
        renderSearchHighlightResultsMobile(searchText, results);
      } else {
        renderSearchResultsMobile(searchText, results);
      }
    }) : null;
  


  
    var mobileSearchInputElem = document.querySelector('#search-mobile');
    var mobileSearchClassElem = document.querySelector('.mobile-search');
    var mobileSearchBtnElems = document.querySelectorAll('.navbar-search');
    var mobileSearchCloseBtnElem = document.querySelector('#search-mobile-close');
    var mobileSearchContainer = document.querySelector('#search-mobile-container');
    var mobileSearchResultsElem = document.querySelector('#search-mobile-results');
    var htmlElem = document.querySelector('html');

    if (mobileSearchClassElem) {
      mobileSearchClassElem.style.display = 'none';
    }

    mobileSearchBtnElems ? 
    mobileSearchBtnElems.forEach(function (elem, idx) {
      elem.addEventListener('click', function () {
        if (mobileSearchContainer) {
          mobileSearchContainer.style.display = 'block';
        }

        if (mobileSearchInputElem) {
          mobileSearchInputElem.focus();
        }

        if (htmlElem) {
          htmlElem.style.overflowY = 'hidden';
        }
      });
    }) : null;

    mobileSearchCloseBtnElem ? 
    mobileSearchCloseBtnElem.addEventListener('click', function() {
      if (mobileSearchContainer) {
        mobileSearchContainer.style.display = 'none';
      }

      if (mobileSearchInputElem) {
        mobileSearchInputElem.value = '';
      }
      
      if (mobileSearchResultsElem) {
        while (mobileSearchResultsElem.firstChild) {
          mobileSearchResultsElem.removeChild(mobileSearchResultsElem.firstChild);
        }
      }

      if (htmlElem) {
        htmlElem.style.overflowY = 'visible';
      }
    }) : null;

    mobileSearchInputElem ?
    mobileSearchInputElem.addEventListener('keydown', function(e) {
      var keyCode = e.which || e.keyCode;
      if (e.key === 'Escape' || keyCode === 27) {
        if (mobileSearchContainer) {
          mobileSearchContainer.style.display = 'none';
        }
        
        if (mobileSearchInputElem) {
          mobileSearchInputElem.value = '';
        }

        if (mobileSearchResultsElem) {
          while (mobileSearchResultsElem.firstChild) {
            mobileSearchResultsElem.removeChild(mobileSearchResultsElem.firstChild);
          }
        }
        if (htmlElem) {
          htmlElem.style.overflowY = 'visible';
        }
      }
    }) : null;
  


  
    function renderSearchResultsMain(searchText, results) {
      var searchBody = document.querySelector('.search-result__body');
      var originUl = searchBody.querySelector('ul');
      var ul = document.createElement('ul');
      
      if (!searchText) {
        searchResult ? searchResult.setAttribute('data-display', 'none') : null;
        summaryContainer ? summaryContainer.setAttribute('data-display', 'block') : null;
      } else if (results) {
        if (results && results.length) {
          results.forEach(function (result) {
            makeLi(ul, result);
          });

          searchResult ? searchResult.setAttribute('data-display', 'block') : null;
          summaryContainer ? summaryContainer.setAttribute('data-display', 'none') : null;
        }
      }

      originUl.parentNode.replaceChild(ul, originUl);
    }

    function renderSearchHighlightResultsMain(searchText, results) {
      var searchBody = document.querySelector('.search-result__body');
      var originUl = searchBody.querySelector('ul');
      var ul = document.createElement('ul');

      if (!searchText) {
        searchResult ? searchResult.setAttribute('data-display', 'none') : null;
        summaryContainer ? summaryContainer.setAttribute('data-display', 'block') : null;
      } else if (results) {
        if (results && results.length) {
          results.forEach(function (result) {
            makeHighlightLi(ul, result);
          });

          searchResult ? searchResult.setAttribute('data-display', 'block') : null;
          summaryContainer ? summaryContainer.setAttribute('data-display', 'none') : null;
        }
      }

      originUl.parentNode.replaceChild(ul, originUl);
    }
  
  });
</script>
    
    


<link rel="stylesheet" href="/css/main.min.css">


    
<meta name="description" content="" />


<meta name="keywords" content="AI,course">

<meta name="created" content="2021-01-07T00:00:00&#43;0000">
<meta name="modified" content="2021-01-07T00:00:00&#43;0000">
<meta property="article:published_time" content="2021-01-07T00:00:00&#43;0000">

<meta name="author" content="ruokeqx">


<meta property="og:site_name" content="ruokeqx&#39;s blog">
<meta property="og:title" content="CS229 Machine Learning——Andrew Ng——Stanford">
<meta property="og:url" content="https://ruokeqx.gitee.io/posts/machine-learning-andrew-ng-stanford/">
<meta property="og:type" content="article">
<meta property="og:description" content="">

<meta name="generator" content="Hugo 0.100.2" />
<meta name="msapplication-TileColor" content="#fff">

<meta name="theme-color" content="#fff">

<meta name="msapplication-navbutton-color" content="#fff">

<meta name="apple-mobile-web-app-status-bar-style" content="#fff">

<link rel="canonical" href="https://ruokeqx.gitee.io/posts/machine-learning-andrew-ng-stanford/">

<link rel="manifest" href="/manifest.json">

  
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <link rel="icon" href="/favicon.png" sizes="any" type="image/png" />
  


    <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "WebPage",
    "headline": "CS229 Machine Learning——Andrew Ng——Stanford",
    "datePublished": "2021-01-07T00:00:00Z",
    "dateModified": "2021-01-07T00:00:00Z",
    "url" : "https://ruokeqx.gitee.io/posts/machine-learning-andrew-ng-stanford/",
    "description": "1 Introduction what is machine learning supervised learning supervised learning regression problem predict a continuous valued output classification problem predict a …",
    "keywords": ["AI","course"],
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": "https://ruokeqx.gitee.io"
    },
    "publisher": {
      "@type": "Organization",
      "name": "ruokeqx's blog",
      "url": "https://ruokeqx.gitee.io"
    }
  }
</script>

    
  
  







  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    
</head>

<body id="root" class="theme__dark">
    <script>
        var localTheme = localStorage.getItem('theme');
        if (localTheme) {
            document.getElementById('root').className = 'theme__' + localTheme;
        }
    </script>
    <div id="container">
        





        <div class="wrapper" data-type="posts" data-kind="page">
            <nav class="navbar scrolling" role="navigation" aria-label="main navigation" data-dir="ltr">
  <div class="navbar__brand">
    
    <a href="/" title="Home" rel="home" class="navbar__logo-link">
      <img src="/logo.png" alt="Home" class="navbar__logo">
    </a>
    
    
      <a href="/" title="Home" rel="home" class="navbar__title-link">
        <h6 class="navbar__title">ruokeqx</h6>
      </a>
    
  </div>

  
<div class="theme theme-mobile" data-ani="true">
  <div class="dropdown">
    <button class="dropdown-trigger navbar__slide-down" aria-label="Select Theme Button" style="" data-ani="true">
      <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24"><path fill="none" d="M24 0H0v24h24V0z"/><path fill="currentColor" d="M6.34 7.93c-3.12 3.12-3.12 8.19 0 11.31C7.9 20.8 9.95 21.58 12 21.58s4.1-.78 5.66-2.34c3.12-3.12 3.12-8.19 0-11.31l-4.95-4.95c-.39-.39-1.02-.39-1.41 0L6.34 7.93zM12 19.59c-1.6 0-3.11-.62-4.24-1.76C6.62 16.69 6 15.19 6 13.59s.62-3.11 1.76-4.24L12 5.1v14.49z"/></svg>      
    </button>
    <div class="dropdown-content select-theme">
      
        
        <a href="#" class="dropdown-item select-theme__item is-active">
          dark
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          light
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          hacker
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          solarized
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          kimbie
        </a>
        
      
    </div>
  </div>
</div>


<div class="mobile-search__btn navbar-search" data-ani="true">
  <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M15.5 14h-.79l-.28-.27c1.2-1.4 1.82-3.31 1.48-5.34-.47-2.78-2.79-5-5.59-5.34-4.23-.52-7.79 3.04-7.27 7.27.34 2.8 2.56 5.12 5.34 5.59 2.03.34 3.94-.28 5.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
</div>

<div id="search-mobile-container" class="mobile-search hide" data-dir="ltr">
  <div class="mobile-search__top">
    <input id="search-mobile" type="text" aria-label="Mobile Search" placeholder="Search" class="mobile-search__top--input"/>
    <div id="search-mobile-close" class="mobile-search__top--icon">
      <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24"><path opacity=".87" fill="none" d="M0 0h24v24H0V0z"/><path fill="currentColor" d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm3.59-13L12 10.59 8.41 7 7 8.41 10.59 12 7 15.59 8.41 17 12 13.41 15.59 17 17 15.59 13.41 12 17 8.41z"/></svg>
    </div>
  </div>
  <div id="search-mobile-results" class="mobile-search__body">
    
  </div>
</div>


<a role="button" class="navbar__burger" aria-label="menu" aria-expanded="false"
  data-ani="true">
  <span aria-hidden="true"></span>
  <span aria-hidden="true"></span>
  <span aria-hidden="true"></span>
</a>
<div class="navbarm__collapse" data-open="false">
  <ul dir="ltr">
    
    
      
      
      
      

      
        <li class="navbarm__menu--item active">
          <a href="/posts">Posts</a>
        </li>
      
      
    
      
      
      
      

      
        <li class="navbarm__menu--item ">
          <a href="/archive">Archive</a>
        </li>
      
      
    
      
      
      
      

      
        <li class="navbarm__menu--item ">
          <a href="/about">About</a>
        </li>
      
      
    

    
      <li class="navbarm__menu--item ">
        <a href="/tags" class="navbarm__menu--term" data-index="0">
          Tags
        </a>
      </li>
    
      <li class="navbarm__menu--item ">
        <a href="/categories" class="navbarm__menu--term" data-index="1">
          Categories
        </a>
      </li>
    
      <li class="navbarm__menu--item ">
        <a href="/series" class="navbarm__menu--term" data-index="2">
          Series
        </a>
      </li>
    
  </ul>
</div>
  <div class="navbar__menu">
  
  
  
<div class="theme" data-ani="true">
  <div class="dropdown">
    <button class="dropdown-trigger navbar__slide-down" aria-label="Select Theme Button" data-ani="true">
      <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24"><path fill="none" d="M24 0H0v24h24V0z"/><path fill="currentColor" d="M6.34 7.93c-3.12 3.12-3.12 8.19 0 11.31C7.9 20.8 9.95 21.58 12 21.58s4.1-.78 5.66-2.34c3.12-3.12 3.12-8.19 0-11.31l-4.95-4.95c-.39-.39-1.02-.39-1.41 0L6.34 7.93zM12 19.59c-1.6 0-3.11-.62-4.24-1.76C6.62 16.69 6 15.19 6 13.59s.62-3.11 1.76-4.24L12 5.1v14.49z"/></svg>      
    </button>
    <div class="dropdown-content select-theme">
      
        
        <a href="#" class="dropdown-item select-theme__item is-active">
          dark
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          light
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          hacker
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          solarized
        </a>
        
        <a href="#" class="dropdown-item select-theme__item ">
          kimbie
        </a>
        
      
    </div>
  </div>
</div>

  
  
  
  
  
  
  
  <a href="/posts" class="navbar__menu-item navbar__slide-down active" dir="ltr" data-ani="true">Posts</a>
  
  
  
  
  
  
  
  <a href="/archive" class="navbar__menu-item navbar__slide-down " dir="ltr" data-ani="true">Archive</a>
  
  
  
  
  
  
  
  <a href="/about" class="navbar__menu-item navbar__slide-down " dir="ltr" data-ani="true">About</a>
  
  
</div>
</nav>
            
            

<main class="single__main main-main">
  
    <nav class="breadcrumb hide" aria-label="breadcrumbs">
  <script>document.querySelector('.breadcrumb').classList.remove('hide')</script>
  <ol>
    
  
  
  
  
  
  <li >
    
      <a href="https://ruokeqx.gitee.io/" class="capitalize">ruokeqx&#39;s blog</a>
    
  </li>
  
  
  <li >
    
      <a href="https://ruokeqx.gitee.io/posts/" class="capitalize">Posts</a>
    
  </li>
  
  
  <li  class="is-active" >
    
      <span>CS229 Machine Learning——Andrew Ng——Stanford</span>
    
  </li>
  
  </ol>
  
</nav>
  
  
  <div class="single ">
    <div class="single__nojs">This page looks best with JavaScript enabled</div>
    <script>document.querySelector('.single').classList.remove('hide'); document.querySelector('.single__nojs').classList.add('hide');</script>
    <h2 class="single__title" data-ani="true">CS229 Machine Learning——Andrew Ng——Stanford</h2>
    <h3 class="single__subtitle"></h3>
    <div class="single__meta">
      
<div class="single__infos">
  <time class="single__info" title="Written At">📅&nbsp;Jan 7, 2021 </time>
  
  &nbsp;&middot;&nbsp; <span class="single__info" title="Reading Time"> ☕&nbsp;43&nbsp;min read </span>
  
  <span class="single__info">
     &middot; 👀<span id="busuanzi_value_page_pv">...</span> views
  </span>
</div>

      
<ul class="single__tags caption">
  
  🏷️
  

  <li><a href="https://ruokeqx.gitee.io/tags/ai/" class="single__tag" title="AI">#AI</a></li>

  <li><a href="https://ruokeqx.gitee.io/tags/course/" class="single__tag" title="course">#course</a></li>

</ul>

    </div>
    <article class="single__contents" data-dir="ltr" data-ani="true">
      
      <h2 id="1-introduction">1 Introduction</h2>
<h3 id="what-is-machine-learning">what is machine learning</h3>
<h3 id="supervised-learning">supervised learning</h3>
<ul>
<li>supervised learning
<ul>
<li>regression problem
<ul>
<li>predict a continuous valued output</li>
</ul>
</li>
<li>classification problem
<ul>
<li>predict a discrete valued output</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>SVM(Support Vector Machine) is a kind of generalized linear classification that classifies data by supervised learning</p>
<h3 id="unsupervised-learning">unsupervised learning</h3>
<ul>
<li>
<p>unsupervised learning</p>
<ul>
<li>Cluster  Algorithm
<ul>
<li>Google news</li>
<li>Facebook friends</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="2-linear-regression-with-one-variable">2. Linear Regression with One Variable</h2>
<h3 id="21-model-representation">2.1 Model Representation</h3>
<p>Linear regression with one variable.<br />
Univariate linear regression.</p>
<p>m —— the number of training examples<br />
x —— input<br />
y —— output<br />
h —— hypothesis function</p>
<p>$h_\theta \left( x \right)=\theta_{0}+\theta_{1}x$</p>
<p><img src="https://img-blog.csdnimg.cn/20201230231127382.png" alt="" /></p>
<h3 id="22-cost-function">2.2 Cost function</h3>
<p>also called square error function or square error cost function.</p>
<p>help figure out how to fit the best possible straight line to our data.</p>
<p>how to choose parameter values to make hypothesis function fit better.($J \left( \theta_0, \theta_1 \right) = \frac{1}{2m}\sum\limits_{i=1}^m \left( h_{\theta}(x ^{(i)})-y ^{(i)} \right)^{2}$)</p>
<h3 id="23-cost-function---intuition-1">2.3 Cost Function - Intuition 1</h3>
<p>For each value of theta one corresponds to a different hypothesis or to a different straight line fit. And for each value of theta one, we could then derive a different value of J of theta one. And value of J of theta one plot the picture on the right.</p>
<p><img src="https://img-blog.csdnimg.cn/20201230234651648.png" alt="" /></p>
<p>The optimization objective for our learning algorithm is we want choose the value of theta one that minimizes J of theta one. This was our objective function for the linear regression.</p>
<h3 id="24-cost-function---intuition-2">2.4 Cost Function - Intuition 2</h3>
<p>1 parameter 2-D plot<br />
2 parameters 3-D plot</p>
<p><img src="https://img-blog.csdnimg.cn/20201231000255460.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20201231000311284.png" alt="" /></p>
<h3 id="25-gradient-descent">2.5 Gradient Descent</h3>
<p>Imagine that this figure shows a hill, you are physically standing at a point one the hill. Gradient descent is to spin 360 degrees around and ask &ldquo;if I were to take a little baby step in some direction, and I want go downhill as quickly as possible, what direction do I take?&rdquo;</p>
<p>Go until you converge to a local minimum. If you start at different point, gradient descent will take you to the second local optimum.</p>
<p><img src="https://img-blog.csdnimg.cn/20210107160258852.jpg" alt="" /></p>
<p>This is <code>batch gradient descent algorithm</code> and $\alpha$ refer to the <code>learning rate</code>. We need  update the $\theta_0$ and $\theta_1$ simultaneously.</p>
<p><img src="https://img-blog.csdnimg.cn/20210107160615637.png" alt="" /></p>
<h3 id="26-gradient-descent-intuition">2.6 Gradient Descent Intuition</h3>
<p>For single variable function, partial derivative equal to derivative.</p>
<p>The direction of the derivative is opposite to the direction to be changed, so $\alpha$ is preceded by a minus sign. Sign of partial derivative refer to the direction you need to go and $\alpha$ refer to the length of your every little step. If $\alpha$ is too small, gradient descent can be slow. If $\alpha$ is too large, gradient descent can overshoot the minimum. It may fail to converge, or even diverge.</p>
<p><img src="https://img-blog.csdnimg.cn/20210107164501320.png" alt="" /></p>
<p>The reason why we don&rsquo;t need to decrease $\alpha$. (automatically take smaller steps)</p>
<p><img src="https://img-blog.csdnimg.cn/20210107170338876.png" alt="" /></p>
<h3 id="27-gradient-descent-for-linear-regression">2.7 Gradient Descent For Linear Regression</h3>
<p>Apply gradient descent to minimum our squared error cost function.</p>
<p>Partial derivative of cost function for linear regression:</p>
<p>$\frac{\partial }{\partial \theta_j}J(\theta_0,\theta_1)=\frac{\partial }{\partial \theta_j}\frac{1}{2m}\sum\limits_{i=1}^m \left( h_{\theta}(x ^{(i)})-y ^{(i)} \right)^{2}$</p>
<p>$j=0$ : $\frac{\partial }{\partial \theta_0}J(\theta_0,\theta_1)=\frac{1}{m}\sum\limits_{i=1}^m \left( h_{\theta}(x ^{(i)})-y ^{(i)} \right)$</p>
<p>$j=1$ : $\frac{\partial }{\partial \theta_1}J(\theta_0,\theta_1)=\frac{1}{m}\sum\limits_{i=1}^m \left( \left( h_{\theta}(x ^{(i)})-y ^{(i)} \right)\cdot {x^{(i)}} \right)$</p>
<p>Cost function for linear regression is always going to be a bowl-shaped function(convex function), it doesn&rsquo;t have any local optima except for the one global optimum.</p>
<p><img src="https://img-blog.csdnimg.cn/202101071818338.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20210107181756756.png" alt="" /></p>
<p>&ldquo;Batch&rdquo;: each step of gradient descent uses all the training examples.</p>
<h2 id="3-linear-algebra-review">3. Linear Algebra Review</h2>
<h3 id="31-matrices-and-vectors">3.1 Matrices and Vectors</h3>
<p>vector is a matrix that has only one column.</p>
<h3 id="32-addition-and-scalar-multiplication">3.2 Addition and Scalar Multiplication</h3>
<p>add or multiply every element</p>
<h3 id="33-matrix-vector-multiplication">3.3 Matrix Vector Multiplication</h3>
<p>$m×n$ matrix times $n×1$ vector equal to $m×1$​ vector</p>
<h3 id="34-matrix-matrix-multiplication">3.4 Matrix Matrix Multiplication</h3>
<p><img src="https://img-blog.csdnimg.cn/20210107230536234.png" alt="" /></p>
<h3 id="35-matrix-multiplication-properties">3.5 Matrix Multiplication Properties</h3>
<p>all matrix:</p>
<p>$A×B≠B×A$(commutative property of multiplication)</p>
<p>$A×(B×C)=(A×B)×C$(associative property of multiplication)</p>
<p>Identity matrix:</p>
<p>identity matrix has ones along the diagonals and zero everywhere else.</p>
<p>$$\begin{bmatrix} 0 &amp; -1 \\ 1 &amp; 0 \end{bmatrix}$$</p>
<p>$AA ^{-1}=A ^{-1}A=I$</p>
<p>$AI=IA=A$</p>
<h3 id="36-inverse-and-transpose">3.6 Inverse and Transpose</h3>
<p>inverse of matrix($A^{-1}$)</p>
<p>only square matrices have inverses.</p>
<p>$AA ^{-1}=A ^{-1}A=I$</p>
<p>transpose:</p>
<p>let A be an <code>m x n</code> matrix, let $B = A^T$.</p>
<p>Then B is an <code>n x m</code> matrix and $B_{ij} =  A_{ji}$.<br />
$$\begin{bmatrix} 1 &amp; 2 &amp; 0 \\ 3 &amp; 5 &amp; 9 \end{bmatrix} = \begin{bmatrix} 1 &amp; 3 \\ 2 &amp; 5 \\ 0 &amp; 9 \end{bmatrix}$$</p>
<h2 id="4-linear-regression-with-multiple-variables">4. Linear Regression with Multiple Variables</h2>
<h3 id="41-multiple-features">4.1 Multiple Features</h3>
<p><img src="https://img-blog.csdnimg.cn/20210108172814770.png" alt="" /></p>
<p>$\left( x_1,x_2,&hellip;,x_n \right)$ stand for multiple variables</p>
<p>$x^{(i)}$ is a vector and it stand for the $i^{th}$ training example</p>
<p>$x^{(2)}=\begin{bmatrix} 1416 \\ 3 \\ 2 \\ 40 \end{bmatrix}$</p>
<p>$x_j^{(i)}$ stand for the value $j$ in $i^{th}$ training example.</p>
<p>$x_2 ^{(2)}=3,x_3 ^{(2)}=2$</p>
<p>the form of the hypothesis:</p>
<p>$h_\theta \left( x \right)=\theta_0+\theta_1x_1+\theta_2x_2+&hellip;+\theta_nx_n$</p>
<p>For convenience of notation, we define $x_0$ to be equals one.</p>
<p>Now, $X$ is a $n+1$ dimensional feature vector; parameters $\theta$ is also a $n+1$ dimensional vector.</p>
<p>$X = \begin{bmatrix} x_0 \\ x_1 \\ x_2 \\ &hellip; \\ x_n \end{bmatrix} \theta = \begin{bmatrix} \theta_0 \\ \theta_1 \\ \theta_2 \\ &hellip; \\ \theta_n \end{bmatrix} \theta^T = \begin{bmatrix} \theta_0 \ \theta_1 \ \theta_2 \ &hellip; \ \theta_n \end{bmatrix}$</p>
<p>$h_\theta \left( x \right)=\theta_0 x_0 + \theta_1 x_1 + \theta_2 x_2+ &hellip; + \theta_n x_n$</p>
<p>$h_\theta \left( x \right)=\theta^TX$</p>
<h3 id="42-gradient-descent-for-multiple-variables">4.2 Gradient Descent for Multiple Variables</h3>
<p>Gradient descent algorithm:</p>
<p><img src="https://img-blog.csdnimg.cn/20210108213854762.png" alt="" /></p>
<p>$J({\theta_0},{\theta_1}&hellip;{\theta_n})=\frac{1}{2m}\sum\limits_{i=1}^m{( h_\theta(x^{(i)})-y^{(i)})^2}$</p>
<p>when $n&gt;=1$:</p>
<p>${\theta_0}:=\theta_0-a\frac{1}{m}\sum\limits_{i=1} ^m{(h_\theta(x ^{(i)})-{y} ^{(i)})}x_0 ^{(i)}$</p>
<p>${\theta_1}:=\theta_1-a\frac{1}{m}\sum\limits_{i=1} ^m{(h_\theta(x ^{(i)})-{y} ^{(i)})}x_1 ^{(i)}$</p>
<p>${\theta_2}:=\theta_2-a\frac{1}{m}\sum\limits_{i=1} ^m{(h_\theta(x ^{(i)})-{y} ^{(i)})}x_2 ^{(i)}$</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">computeCost</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">theta</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">inner</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(((</span><span class="n">X</span> <span class="o">*</span> <span class="n">theta</span><span class="o">.</span><span class="n">T</span><span class="p">)</span> <span class="o">-</span> <span class="n">y</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">inner</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="43-gradient-descent-in-practice-i---feature-scaling">4.3 Gradient Descent in Practice I - Feature Scaling</h3>
<p>Feature scaling:</p>
<p>If you make sure that the features are on a similar scale, then gradient descents can converge more quickly.</p>
<p>If $\theta_1$ is larger than $\theta_2$, the cost function will like picture on the left. And if you run gradient descent on this sort of cost function, your gradients may end up taking a long time and can oscillate back and forth and take a long time before it can finally find its way to the global minimum.</p>
<p>A useful thing to do is to scale the features. If $x_1, x_2$ like on the right, the contours may look more like circles, and if you run gradient descent on a cost function like this, then gradient descent  (you can show mathematically) can find a much more direct path to global minimum rather than much more complicated trajectory.</p>
<p><img src="https://img-blog.csdnimg.cn/20210108220730376.png" alt="" /></p>
<p>When we performing feature scaling, what we often to do is get every feature into approximately range $[-1,1]$ nether too small nor too large.</p>
<p><img src="https://img-blog.csdnimg.cn/20210108222037197.png" alt="" /></p>
<p>When performing feature scaling, sometimes people will also do what&rsquo;s called mean normalization.</p>
<p>Place $x_i$ with $x_i-\mu_i$ to make feature have approximately zero mean.</p>
<p>More general rule: replace $x_1 &lt;- \frac{(x_1-\mu_1)}{s_1}$, $\mu1$ is the average value of $x_1$ in the training sets, ans $s_1$ is the standard deviation of that feature. Then it will be roughly into these sorts of ranges.</p>
<p><img src="https://img-blog.csdnimg.cn/20210108223306734.png" alt="" /></p>
<h3 id="44-gradient-descent-in-practice-ii---learning-rate">4.4 Gradient Descent in Practice II - Learning Rate</h3>
<p>See 2.6 Gradient Descent Intuition</p>
<p>$\alpha=0.01，0.03，0.1，0.3，1，3，10$</p>
<h3 id="45-features-and-polynomial-regression">4.5 Features and Polynomial Regression</h3>
<p><img src="https://img-blog.csdnimg.cn/20210115233337679.png" alt="" /></p>
<p>To predict the prize of the house we have two paras $h_\theta(x)=\theta_0+\theta_1\times{frontage}+\theta_2\times{depth}$</p>
<p>if we let $x=frontage * depth=area$ then $h_\theta(x)=\theta_0+\theta_1x$</p>
<p>sometimes linear regression don&rsquo;t fit all data, so maybe you want to fit a quadratic model like $h_\theta(x)=\theta_0+\theta_1x_1+\theta_2x_2^2$, it may be not fit well, then you can choose to use instead a cubic function line$h_\theta(x)=\theta_0+\theta_1x_1+\theta_2x_2 ^2+\theta_3x_3 ^3$</p>
<p><img src="https://img-blog.csdnimg.cn/20210115233238383.jpg" alt="" /></p>
<p>$h_\theta(x)=\theta_0+\theta_1(size)+\theta_2(size)^2$</p>
<p>$h_\theta(x)=\theta_0+\theta_1(size)+\theta_2\sqrt{size}$</p>
<p>polynomial regression fit a polynomial, like a quadratic function or a cubic function, to your data. Be aware that you have a choice in what features to use, and by designing different features you can fit more complex functions to your data than just fitting a straight line to the data, and in particular, you can fit polynomial functions as well.</p>
<p>PS: it is important to apply feature scaling if you are using gradient descent to get them into comparable ranges of values.</p>
<h3 id="46-normal-equation">4.6 Normal Equation</h3>
<p>Normal equation, which for some linear regression problems, will git us much better way to solve for the optimal value of the parameters theta.</p>
<p>So far the algorithm that we&rsquo;ve been using for linear regression is gradient descent where in order to minimize the cost function $J  of \theta$, we would take this iterative algorithm that takes many steps, multiple iterations of gradient descent to converge to the global minimum. In contrast, the normal equation will give us a method to solve for theta analytically, so that rather than needing to run this iterative algorithm, we can instead just solve for the optimal value for theta all at one go, so that in basically one step you get to the optimal value right there.</p>
<p>Set $\theta=(X ^TX) ^-1X ^Ty$, this will give you the value of $\theta$ that minimizes your cost function.</p>
<p><img src="https://img-blog.csdnimg.cn/20210116002338478.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20210116002334359.jpg" alt="" /></p>
<p>Normal equation don&rsquo;t need feature scaling, thought it is important for linear regression.</p>
<p>CHOICES:</p>
<table>
<thead>
<tr>
<th>Gradient descent</th>
<th>Normal equation</th>
</tr>
</thead>
<tbody>
<tr>
<td>need to choose $\alpha$</td>
<td>no need to choose $\alpha$</td>
</tr>
<tr>
<td>need many iterations</td>
<td>don&rsquo;t need to iterate</td>
</tr>
<tr>
<td>works well even when $n$ is large</td>
<td>need to compute$(X ^TX) ^{-1}$</td>
</tr>
<tr>
<td></td>
<td>inverse O(n^3), slow if $n$ is very large</td>
</tr>
</tbody>
</table>
<h3 id="47-normal-equation-noninvertibility">4.7 Normal Equation Noninvertibility</h3>
<p>What if the matrix X transpose X is non-invertible? Some matrices do not have an inverse, we call those non-invertible matrices, singular or degenerate matrices. The issue or the problem of X transpose X being non-invertible should happen pretty rarely.</p>
<p>If X transpose X is non-invertible, there are usually two most common causes: The first cause is if somehow, in your learning problem, you have redundant features, concretely, if you try to predict housing prices and if $x_1$ is the size of house in square-feet and $x_2$ is the size of the house in square-meters(1 meter is equal to 3.28 feet), your two features are <code>related via a linear equation</code>, then matrix X transpose X will be non-invertible. Second thing that can cause it to be non-invertible is if you&rsquo;re trying to run a learning algorithm with a lot of features. Concretely, if m is less than or equal to n.</p>
<p><img src="https://img-blog.csdnimg.cn/20210116113325536.png" alt="" /></p>
<h2 id="5-octave-tutorial">5. Octave Tutorial</h2>
<p>omitted</p>
<h2 id="6-logistic-regression">6. Logistic Regression</h2>
<h3 id="61-classification">6.1 Classification</h3>
<p>Logistic regression, actually a classification algorithm, has the property that the output the predictions of logistic regression are always between zero and one, and doesn&rsquo;t become bigger than one or become less than zero.</p>
<h3 id="62-hypothesis-representation">6.2 Hypothesis Representation</h3>
<p>Hypothesis representation, that is what is the function we&rsquo;re going to use to represent our hypothesis when we have classification problem.</p>
<p>When we were using linear regression, $h_\theta(x)=\theta^Tx$ was the form of a hypothesis. For logistic regression, I&rsquo;m going to modify this a little bit and make the hypothesis $h_\theta(x) = g(\theta^Tx)$, where g is $g(z)=\frac1{1+e^{-z} }$, this is called sigmoid function or logistic function(give rise to the name logistic regression)(Sigmoid function and logistic function are basically synonyms and mean the same thing. So the two terms are basically interchangeable).</p>
<p><img src="https://img-blog.csdnimg.cn/2021011614343212.png" alt="" /></p>
<p>$h_\theta(x) = \text{estimated probability that y=1 on input x}$</p>
<p>$h_\theta(x) = P(y=1|x;\theta)$ and $P(y=0|x;\theta)+P(y=1|x;\theta)=1$</p>
<h3 id="63-decision-boundary">6.3 Decision Boundary</h3>
<p>If $h_\theta(x)=g(\theta_0+\theta_1x_1+\theta_2x_2)$ and let $\theta=\begin{bmatrix} -3 \\ 1 \\1 \end{bmatrix}$</p>
<p>$x_1+x_2&gt;=3$ is decision boundary.</p>
<p><img src="https://img-blog.csdnimg.cn/20210116145752337.png" alt="" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">sigmoid</span><span class="p">(</span><span class="n">z</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">   <span class="k">return</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">z</span><span class="p">))</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="64--cost-function">6.4  Cost Function</h3>
<p>J of $\theta$ ends up being a non-convex function if we are to define it as the squared cost function. We need to come up with a different cost function that is convex and so that we can apply a great algorithm like gradient descent and be guaranteed to find a global minimum.</p>
<p>Here&rsquo;s a cost function that we&rsquo;re going to use for logistic regression.</p>
<p><img src="https://img-blog.csdnimg.cn/20210116151424414.png" alt="" /></p>
<p>This function will penalize learning algorithm by a very large cost.</p>
<p><img src="https://img-blog.csdnimg.cn/20210116154703261.png" alt="" /></p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">cost</span><span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">  <span class="n">theta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="n">X</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="n">first</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="p">(</span><span class="o">-</span><span class="n">y</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">sigmoid</span><span class="p">(</span><span class="n">X</span><span class="o">*</span> <span class="n">theta</span><span class="o">.</span><span class="n">T</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">  <span class="n">second</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="p">((</span><span class="mi">1</span> <span class="o">-</span> <span class="n">y</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">sigmoid</span><span class="p">(</span><span class="n">X</span><span class="o">*</span> <span class="n">theta</span><span class="o">.</span><span class="n">T</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">  <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">first</span> <span class="o">-</span> <span class="n">second</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">X</span><span class="p">))</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="65-simplified-cost-function-and-gradient-descent">6.5 Simplified Cost Function and Gradient Descent</h3>
<p>Cost function can be written in a simple one line: $cost(h_\theta(x),y)=-ylog(h_\theta(x))-(1-y)log(1-h_\theta(x))$</p>
<p>Then the cost function would be $J(\theta)=\frac1m\sum\limits_{i=1} ^mCost(h_\theta(x ^{(i)},y ^{(i)})=-\frac1m\sum\limits_{i=1} ^m[y ^{(i)}log(h_\theta(x ^{(i)}))+(1-y ^{(i)})log(1-h_\theta(x ^{(i)}))]$</p>
<p>This cost function can be derived from statistics using the principle of maximum likelihood estimation, which is convex and find parameters $\theta$ for different models efficiently.</p>
<p>Given this function, in order to fit the parameters, what we&rsquo;re going to do then is try to find the parameters $\theta$ that minimizes $j(\theta)$.${\underset\theta\min}j(\theta)$, this will give us a set of $\theta$. Finally if we&rsquo;re given a new example with some et of features X. We can then take the thetas that we fit our training set and output our prediction as this $h_\theta(x)=\frac1{1+e ^{-\theta ^Tx}}$.</p>
<p>The way we are using to minimize the cost function is using gradient descent. If we want to minimize it as a function of $\theta$. Here&rsquo;s our usual template for gradient descent, where we repeatedly update each parameter by updating it as itself minus a learning rate alpha times derivative term.<br />
$$<br />
\text{Want }min_\theta j(\theta):<br />
\text{Repeat }<br />
\theta_j:=\theta_j-\alpha\frac\partial{\partial \theta_j}j(\theta)<br />
\text{ Simultaneous update all }\theta_j<br />
$$<br />
This algorithm looks identical to linear regression! So are they different algorithm or not? What have changed is $h_\theta(x)$, $h_\theta(x)=\theta^TX$ in linear regression and $h_\theta(x)=\frac1{1+e ^{-\theta ^Tx}}$ in logistic function. So even though the update rule looks cosmetically identical, because the definition of the hypothesis has changed, this is actually not the same thing as gradient descent for linear regression.</p>
<p>Feature scaling can help gradient descent converge faster for linear regression. The idea of feature scaling also applies to gradient descent for logistic regression.</p>
<h3 id="66-advanced-optimization">6.6 Advanced Optimization</h3>
<p><img src="https://img-blog.csdnimg.cn/20210117102730848.png" alt="" /></p>
<h3 id="67-multi-class-classification_-one-vs-all">6.7 Multi-class Classification_ One-vs-all</h3>
<p>Turn training set into three separate binary classification problems.</p>
<p><img src="https://img-blog.csdnimg.cn/20210117104352343.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/2021011710481653.png" alt="" /></p>
<h2 id="7-regularization">7. Regularization</h2>
<h3 id="71-the-problem-of-overfitting">7.1 The Problem of Overfitting</h3>
<p>When you apply algorithm to certain ML applications, thry can run into a problem called overfitting, that can cause them to perform very poorly.</p>
<p>Try too hard to fit the training set, so that it even fails to generalize to new examples.</p>
<p>Here is an instance of overfitting, and og a hypothesis having high variance and not really, and being unlikely to generalize well to new examples.</p>
<p><img src="https://img-blog.csdnimg.cn/20210117110052840.png" alt="" /></p>
<p>Debugging and diagnosing</p>
<p>recognize when overfitting and also when underfitting may be occurring.</p>
<p>Options:</p>
<ul>
<li>
<ol>
<li>Reduce number of features.</li>
</ol>
<ul>
<li>Manually select which features keep.</li>
<li>Model selection algorithm.</li>
</ul>
</li>
</ul>
<p>Throwing away some features also throwing away some information.</p>
<ul>
<li>
<ol start="2">
<li>Regularization</li>
</ol>
<ul>
<li>Keep all the features, but reduce magnitude/values of parameters$\theta_j$.</li>
<li>Works well when we have a lot of features, each of which contributes a bit to predicting y.</li>
</ul>
</li>
</ul>
<h3 id="72-cost-function">7.2 Cost Function</h3>
<p>The idea of regularization is if we have small values for the parameters, it usually correspond to having a simpler hypothesis.</p>
<p>In example, we penalize just $\theta_3 \text{ and }\theta_4$, make $\theta_3 \text{ and }\theta_4$ small and gave us a simpler hypothesis.</p>
<p>It is hard to pick in advance which are the ones that are less likely to be relevant. So in regularization, what we are going to do is take our cost function, and modify the cost function to shrink all of my parameters.</p>
<p>$J(\theta)=\frac1{2m}[\sum\limits_{i=1} ^m{(h_\theta(x ^{(i)})-y ^{(i)})} ^2+\lambda \sum\limits_{j=1} ^n{\theta_j ^2}]$</p>
<p>$\lambda$ is called regularization parameter. And what lambda does, is controls a trade off between two different goals. The first goal is captured by the first term of the objective, is that we would like to fit the training set well. And the second goal is we want to keep the parameters small, and that&rsquo;s captured by the second term, by the regularization objective, and by regularization term.</p>
<p>What $\lambda$ does is the controls the trade off between the goal of fitting the training set well and the goal of keeping the parameter small, and therefore keeping the hypothesis relatively simple to avoid overfitting.</p>
<h3 id="73-regularized-linear-regression">7.3 Regularized Linear Regression</h3>
<p>Gradient descent：</p>
<p>In regularization, we penalize the parameters $\theta_1\theta_2$ and so on up to $\theta_n$, but we don&rsquo;t penalize $\theta_0$, so when we modify this algorithm for regularized linear regression, we&rsquo;re going to end up treating $\theta_0$ slightly differently.</p>
<p>Repeat  until​ convergence​{</p>
<p>​	$\theta_0:={\theta_0}-a\frac1m\sum\limits_{i=1} ^m((h_\theta(x ^{(i)})-y ^{(i)})x_0 ^{(i)})$</p>
<p>​	$\theta_j:=\theta_j-a[\frac1m\sum\limits_{i=1} ^m(h_\theta(x ^{(i)})-y ^{(i)})x_j ^{(i)}+\frac\lambda m\theta_j]$</p>
<p>​										$for$ $j=1,2,&hellip;n$</p>
<p>}</p>
<p>If you group all the terms together that depending on $\theta_j$, you can show that this update can be written equivalently as follows.</p>
<p>$\theta_j:=\theta_j(1-a\frac\lambda m)-a\frac1m\sum\limits_{i=1} ^m({h_\theta}(x ^{(i)})-y ^{(i)})x_j ^{(i)}$</p>
<p>Since $\alpha$ is small and m is big, so $(1-\alpha\frac\lambda m)$ is a number that a little bit less than one. That mean we&rsquo;re shrinking the parameter a little bit, and then we&rsquo;re performing similar update as before. Mathematically, what it&rsquo;s doing is exactly gradient descent on the cost function $j \text{ of } \theta$ that uses the regularization term.</p>
<p>Normal equation:</p>
<p>If you are using regularization, then this formula would add a matrix inside.</p>
<p><img src="https://img-blog.csdnimg.cn/20210118105613201.png" alt="" /></p>
<p>This new formula for $\theta$ is one that will give you the global minimum of $j$ of $\theta$.</p>
<p>non-invertibility:</p>
<p>If you have fewer examples than feature, then this matrix X transpose X will be non-invertible, or singular(degenerate).</p>
<p>So long as the regularization parameter $\lambda$ &gt;0, it is actually possible to prove that this matrix X transpose X plus parameter times this funny matrix will not be singular.</p>
<p><img src="https://img-blog.csdnimg.cn/20210118110546254.png" alt="" /></p>
<h3 id="74-regularized-logistic-regression">7.4 Regularized Logistic Regression</h3>
<p>$J(\theta)=\frac1m\sum\limits_{i=1} ^m[-y ^{(i)}\log( h_\theta(x ^{(i)}))-(1-y ^{(i)})\log(1-h_\theta( x ^{(i)}) )]+\frac{\lambda }{2m}\sum\limits_{j=1} ^n\theta_j ^2$</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">costReg</span><span class="p">(</span><span class="n">theta</span><span class="p">,</span> <span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">learningRate</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">theta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">X</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">first</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="p">(</span><span class="o">-</span><span class="n">y</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">sigmoid</span><span class="p">(</span><span class="n">X</span><span class="o">*</span><span class="n">theta</span><span class="o">.</span><span class="n">T</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">    <span class="n">second</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">multiply</span><span class="p">((</span><span class="mi">1</span> <span class="o">-</span> <span class="n">y</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">sigmoid</span><span class="p">(</span><span class="n">X</span><span class="o">*</span><span class="n">theta</span><span class="o">.</span><span class="n">T</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">    <span class="n">reg</span> <span class="o">=</span> <span class="p">(</span><span class="n">learningRate</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">X</span><span class="p">))</span><span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">power</span><span class="p">(</span><span class="n">theta</span><span class="p">[:,</span><span class="mi">1</span><span class="p">:</span><span class="n">theta</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span><span class="mi">2</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">first</span> <span class="o">-</span> <span class="n">second</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">X</span><span class="p">))</span> <span class="o">+</span> <span class="n">reg</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>Repeat  until convergence{</p>
<p>$\theta_0:=\theta_0-a\frac1m\sum\limits_{i=1} ^m((h_\theta(x ^{(i)})-y ^{(i)})x_0 ^{(i)})$</p>
<p>$\theta_j:=\theta_j-a[\frac1m\sum\limits_{i=1} ^m(h_\theta(x ^{(i)})-y ^{(i)})x_j ^{(i)}+\frac{\lambda }{m}\theta_j]$</p>
<p>$for$ $j=1,2,&hellip;n$<br />
}</p>
<p>This cosmetically looks identical to what we had for linear regression. But of course is not the same algorithm as we had,  because now the hypothesis is defined using $h_\theta(x)=\frac1{1+e ^{-\theta ^Tx}}$.</p>
<h2 id="8-neural-networks-representation">8. Neural Networks: Representation</h2>
<h3 id="81-non-linear-hypotheses">8.1 Non-linear Hypotheses</h3>
<p>If we were try to learn a nonlinear hypothesis by including all the quadratic features, it was too large to be reasonable. So simple logistic regression together with adding in maybe the quadratic or the cubic features that&rsquo;s just not a good way to learn complex nonlinear hypotheses when n is large, because you just end up with too many features.</p>
<p>Neural network turns out to be a much better way to learn complex nonlinear hypotheses, even when your input feature space, even when n is large.</p>
<h3 id="82-neurons-and-the-brain">8.2 Neurons and the Brain</h3>
<p>omitted</p>
<h3 id="83-model-representation-i">8.3 Model Representation I</h3>
<p><img src="https://img-blog.csdnimg.cn/2021011817142029.jpg" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20210118171447489.png" alt="" /></p>
<h3 id="84-model-representation-ii">8.4 Model Representation II</h3>
<p>Forward propagation: Vectorized implementation</p>
<p><img src="https://img-blog.csdnimg.cn/2021011817210825.png" alt="" /></p>
<p>The right part of the picture looks a lot like logistic regression where what we&rsquo;re doing is we&rsquo;re using last node, that&rsquo;s just the logistic regression unit and we&rsquo;re using that to make a prediction h of x. The output $h_\Theta(x)=g(\Theta_0 ^{(2)}a_0 ^{(2)}+\Theta_1 ^{(2)}a_1 ^{(2)}+\Theta_2 ^{(2)}a_2 ^{(2)}+\Theta_3 ^{(2)}a_3 ^{(2)})$. $a_0,a_1,a_2,a_3$ are given by three given units. This is awfully <font color=red>like the standard logistic regression model.</font> But where the features fed into logistic regression are these values <font color=red>computed by the hidden layer.</font> Concretely, the function mapping from layer 1 to layer 2, that is determined by some other set of parameters, theta 1.</p>
<p><img src="https://img-blog.csdnimg.cn/20210119090553941.png" alt="" /></p>
<h3 id="85-examples-and-intuitions-i">8.5 Examples and Intuitions I</h3>
<p>Neural networks can be used to learn complex nonlinear hypotheses.</p>
<p>AND function:</p>
<p><img src="https://img-blog.csdnimg.cn/20210119094842340.png" alt="" /></p>
<p>OR function:</p>
<p><img src="https://img-blog.csdnimg.cn/20210121143133503.png" alt="" /></p>
<p>By taking different set of $\theta$, a single neurons in a neural network can be used to compute logical function.</p>
<h3 id="86-examples-and-intuitions-ii">8.6 Examples and Intuitions II</h3>
<p><img src="https://img-blog.csdnimg.cn/20210119102000426.png" alt="" /></p>
<h3 id="87-multiclass-classification">8.7 Multiclass Classification</h3>
<p>We have 4 logistic regression classifiers, each of which is trying to recognize one of the four classes that we want to distinguish amongst.</p>
<p><img src="https://img-blog.csdnimg.cn/20210119103003397.png" alt="" /></p>
<h2 id="9-neural-networks-learning">9. Neural Networks: Learning</h2>
<h3 id="91-cost-function">9.1 Cost Function</h3>
<p>The cost function we use for the neural network is going to be a generalization of the one that we use for logistic regression.</p>
<p>Logistic regression:</p>
<p>$J(\theta)=-\frac1m[\sum_\limits{i=1} ^{m}y ^{(i)}\log h_\theta(x ^{(i)})+(1-y ^{(i)})log(1-h_\theta(x ^{(i)}))]+\frac\lambda {2m}\sum_\limits{j=1} ^n\theta_j ^2$</p>
<p>Neural network now outputs vectors in $R_K$, where K might be equal to 1 if we have binary classification problem. $(h_\Theta(x))_i = i^{th} \text{ output}$. That is h of x is a K dimensional vector. The subscript i just selects out ith element of the vector that is output by the neural network.</p>
<p>Neural network:</p>
<p>$J(\Theta) = -\frac1m [ \sum\limits_{i=1}^m \sum\limits_{k=1}^k y_k^{(i)} \log (h_\Theta(x^{(i)})) _k + ( 1 - y_k ^{(i)} ) \log ( 1- ( h_\Theta ( x^{(i)} ) )_k ) ] + \frac\lambda {2m} \sum\limits_{l=1}^{L-1} \sum\limits_{i=1}^{s_l} \sum\limits_{j=1} ^{s_{l+1}} ( \Theta_{ji} ^{(l)} ) ^2$</p>
<h3 id="92-backpropagation-algorithm">9.2 Backpropagation Algorithm</h3>
<p>What we&rsquo;d like to do is try to find parameters $\theta$ to try to minimize $J(\theta)$.</p>
<p>This is our vectorized implementation of forward propagation and allows us compute thee activation values for all the neurons in our neural network.</p>
<p><img src="https://img-blog.csdnimg.cn/20210129092203852.png" alt="" /></p>
<p>Next, in order to compute the derivatives, we&rsquo;re going to use an algorithm called back propagation. The intuition of the back propagation algorithm is that for each node we&rsquo;re going to compute the term $\delta ^{(l)}_j$ that&rsquo;s going to somehow <font color='red'>represent the &ldquo;error&rdquo; of node j in the layer l.</font></p>
<p>Recall $a ^{(l)}_j$ does the activation of the j of unit in layer l. So this $\delta$ term is in some sense going to capture our error in the activation of that neural.</p>
<p>$\delta ^{(4)}_j=a ^{(4)}_j-y_j$.</p>
<p>If you think of $\delta$$\alpha$ and y as vectors then you can take those and come up with a vectorized implementation of it.</p>
<p>$\delta ^{(4)}=a ^{(4)}-y$ Here, each of these is a vector whose dimension is equal to the number of output units in out network.</p>
<p>So we now got $\delta ^{(4)}$. What we do next is compute the delta terms for the earlier layers in our network.</p>
<p>Here&rsquo;s a formula for computing $\delta(3)$ , $\delta^{(3)} = (\Theta ^ {(3)}) ^T\delta ^{(4)}\ast g&rsquo;(z ^ {(3)})$. The term g prime of z3, that formally is actually the derivative of the activation function g evaluated at the inputs given by z3. You can get $g&rsquo;(z ^{(3)}) = a ^{(3)}\ast (1-a ^{(3)})$ if put z3 in sigmoid function.</p>
<p>$\delta^{(2)} = (\Theta ^ {(2)}) ^T\delta ^{(3)}\ast g&rsquo;(z ^ {(2)})$ $g&rsquo;(z ^{(2)}) = a ^{(2)}\ast (1-a ^{(2)})$</p>
<p>And there is no delta 1 term, because the first layer corresponds to the input layer and that&rsquo;s just the feature we observed in our training sets, so that doesn&rsquo;t have any error associated with that.</p>
<p>The name back propagation comes from the fact that we start by computing the delta term for the output layer and then we go back a layer and compute the delta terms for the third hidden layer and then we go back another step to compute $\delta(2)$ and so, we&rsquo;re sort of back propagating the errors from the output layer to layer 3 to layer 2.</p>
<p>Ignoring lambda or alternatively the regularization term lambda will equal to 0 $\frac{\partial}{\partial\Theta_{ij} ^{(l)}}J(\Theta)=a_{j} ^{(l)} \delta_{i} ^{l+1}$</p>
<p><img src="https://img-blog.csdnimg.cn/20210211122449154.png" alt="" /></p>
<p>Suppose we have a training set of m examples. The first thing we&rsquo;re going to do is to set these $\delta ^{(l)}_{ij}$. Triangular symbol is the capital Greek alphabet delta. $\Delta ^{(l)}_{ij}$.</p>
<p>The delta is to be used as accumulators that will slowly add things in order to compute these partial derivatives.</p>
<p>Next we&rsquo;re going to loop through our training set. For the ith iteration, we&rsquo;re going to working with the training example $(x ^{(i)},y ^{(i)})$.</p>
<p>Set $a ^{(1)} = x ^{(i)}$ and perform forward propagation to compute the activations for all layer $a ^{(l)} l=2,3,&hellip;,L$.</p>
<p>Next we&rsquo;re going to use output label $y ^{(i)}$ to compute the term for $\delta ^{(L)}$ for the output there. $\delta ^{(i)} = a ^{(L)}-y ^{(i)}$.</p>
<p>Then we&rsquo;re going to use the back propagation algorithm to compute $\delta ^{(L-1)},\delta ^{(L-2)},&hellip;,\delta ^{(2)}$. No delta 1 because we don&rsquo;t associate an error term with the input layer.</p>
<p><img src="https://img-blog.csdnimg.cn/20210211124222170.png" alt="" /></p>
<h3 id="93-backpropagation-intuition">9.3 Backpropagation Intuition</h3>
<p>Forward propagation:<br />
<img src="https://img-blog.csdnimg.cn/20210221154251552.png" alt="" /></p>
<p>Back propagation:</p>
<p>One useful intuition is that back propagation is computing these $\delta ^{(l)}_j$ and we can think of these as the call error of the activation value.</p>
<p><img src="https://img-blog.csdnimg.cn/20210221155932550.png" alt="" /></p>
<h3 id="94-implementation-note-unrolling-parameters">9.4 Implementation Note Unrolling Parameters</h3>
<p>Use back propagation to compute the derivatives of your cost function.</p>
<p>One implementation detail of unrolling parameters from matrices into vectors. Then you can pass this to an advanced authorization algorithm like fminunc for getting our for a gradient there.</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">function</span><span class="o">[</span>jVal,gradient<span class="o">]</span> <span class="o">=</span> costFunction<span class="o">(</span>theta<span class="o">)</span>
</span></span><span class="line"><span class="cl"><span class="c1"># gradient-&gt;R^(n+1) theta-&gt;R^(n+1) initialTheta-&gt;R^(n+1) vectors</span>
</span></span><span class="line"><span class="cl">...
</span></span><span class="line"><span class="cl"><span class="nv">optTheta</span> <span class="o">=</span> fminunc<span class="o">(</span>@costFunction, initialTheta, options<span class="o">)</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p><img src="https://img-blog.csdnimg.cn/20210221163339652.png" alt="" /></p>
<h3 id="95-gradient-checking">9.5 Gradient Checking</h3>
<p>When $\Theta$ is real number</p>
<p><img src="https://img-blog.csdnimg.cn/20210221164129707.png" alt="" /></p>
<p>When $\Theta$ is a vector parameter</p>
<p><img src="https://img-blog.csdnimg.cn/20210221164420395.png" alt="" /></p>
<p>The top partial derivative of the cost function with respect to every parameter in our network. And we can then take the gradient that we got from back prop.</p>
<p>Check that $gradApprox\approx DVec$ If so, that implementation of back prop is correct.</p>
<p><img src="https://img-blog.csdnimg.cn/20210221165229970.png" alt="" /></p>
<p>The numerical gradient checking code is a very computationally expensive, a very slow way to try to approximate the derivative. Whereas in contrast, back propagation algorithm is much more computationally efficient way of computing the derivatives. <font color=red>Once you&rsquo;ve verified your implementation of back propagation is corrct, you should turn off gradient checking</font></p>
<p><img src="https://img-blog.csdnimg.cn/20210221165925590.png" alt="" /></p>
<h3 id="96-random-initialization">9.6 Random Initialization</h3>
<p>If set zeros, after each update, $\Theta$ will always be same. The way to solve is to use random initialization.</p>
<p><img src="https://img-blog.csdnimg.cn/20210221170917891.png" alt="" /></p>
<h3 id="97-putting-it-together">9.7 Putting It Together</h3>
<ul>
<li>Pick a network architecture(connectivity pattern between the neurons)
<ul>
<li>Reasonable default 1 hidden layer. The more hidden units in each layer the better(slow)</li>
</ul>
</li>
</ul>
<p>Training a neural network</p>
<ol>
<li>Randomly initialize weights</li>
<li>Implement forward propagation to get $h_\Theta(x ^{(i)})$ for any $x ^{(i)}$</li>
<li>Implement code to compute cost function $J(\Theta)$</li>
<li>Implement backprop to compute all partial derivatives</li>
<li>Use gradient checking to compare partial derivatives computed using backpropagation and numerical estimate of gradient of $J(\Theta)$.</li>
<li>Use gradient descent or advanced optimization method with backpropagation to try minimize $J(\Theta)$ as a function of parameters $\Theta$.</li>
</ol>
<h3 id="98-autonomous-driving">9.8 Autonomous Driving</h3>
<h2 id="10-advice-for-applying-machine-learning">10. Advice for Applying Machine Learning</h2>
<h3 id="101-deciding-what-to-try-next">10.1 Deciding What to Try Next</h3>
<p>When you test your hypothesis on a new set of houses, you find that it makes unacceptably large errors in its predictions. What should you try next?</p>
<ul>
<li>Get more training examples</li>
<li>Try smaller sets of features</li>
<li>Try getting additional features</li>
<li>Try adding polynomial features($x ^2_1,x ^2_2,x_1x_2,etc.$)</li>
<li>Try decreasing $\lambda$</li>
<li>Try increasing $\lambda$</li>
</ul>
<p>In the next two videos after this, I&rsquo;m going to first talk about how to evaluate learning algorithms.</p>
<p>In the next two videos after that, I&rsquo;m going to talk about these techniques which are called the machine learning diagnostics.(A test that you can run to gain insight what is/isn’t working with a learning algorithm, and gain guidance as to how best to improve its performance.)</p>
<h3 id="102-evaluating-a-hypothesis">10.2 Evaluating a Hypothesis</h3>
<p>The standard way to evaluate a learned hypothesis is as follows.</p>
<p>Split the dataset into training set and test set.</p>
<ul>
<li>
<p>Typical procedure for how you would train and test the learning algorithm maybe linear regression.</p>
<ul>
<li>First, Learn parameter $\Theta$ from training data(minimizing training error $J(\Theta)$)</li>
<li>Compute test set error.</li>
</ul>
</li>
<li>
<p>Training/testing procedure for logistic regression</p>
<ul>
<li>Learn parameter $\Theta$ for logistic regression</li>
<li>Compute test error.</li>
<li>Misclassification error (0/1 misclassification error)</li>
</ul>
</li>
</ul>
<h3 id="103-model-selection-and-train-validation-test-sets">10.3 Model Selection and Train Validation Test Sets</h3>
<p>We will see what &ldquo;Switch data into train, validation and test sets. &quot; are and how to use them to do model selection.</p>
<p>Model selection: choose a degree of polynomial and fit that model and also get some estimate of how well your fitted hypothesis was generalize to new examples.</p>
<p>Go over and get all parameters $\Theta ^1\Theta ^2&hellip;\Theta ^{10}$ , look at cross validation set error, see which model has the lowest cross validation set error.</p>
<p>Instead of using the test set to select the model, we&rsquo;re instead going to use the validation set, or the cross validation set, to select the model.</p>
<p>Use the test set to measure or to estimate the generalization error of the model that was selected by the algorithm.</p>
<p><img src="https://img-blog.csdnimg.cn/20210223152004168.png" alt="" /></p>
<h3 id="104-diagnosing-bias-vs-variance">10.4 Diagnosing Bias vs. Variance</h3>
<p>underfitting problem or an overfitting problem.</p>
<p>Bias(underfit): training error high cross validation error high<br />
Variance(overfit): training error low cross validation error high</p>
<p><img src="https://img-blog.csdnimg.cn/20210223155046368.png" alt="" /></p>
<h3 id="105-regularization-and-biasvariance">10.5 Regularization and Bias/Variance</h3>
<p>How does regularization affect the bias ans variance of a learning algorithm?</p>
<p>How can we automatically choose a good value for the regularization parameter $\lambda$?</p>
<p>Like in model selection</p>
<ol>
<li>choose different $\lambda$</li>
<li>minimize the cost function and get parameters vector $\Theta$</li>
<li>use cross validation set to evaluate them</li>
<li>choose the lowest error</li>
<li>look at how well it does on the test set</li>
</ol>
<p><img src="https://img-blog.csdnimg.cn/20210223161221344.png" alt="" /></p>
<p>You can plot $J_{train}(\Theta)$ and $J_{cv}(\Theta)$. When $\lambda$ is small it would be overfiting(variance), when $\lambda$ is large it would be lessfiting(bias).</p>
<p><img src="https://img-blog.csdnimg.cn/20210223162001528.png" alt="" /></p>
<h3 id="106-learning-curves">10.6 Learning Curves</h3>
<p>Learning curve is a useful tool that can use to diagnose if a physical learning algorithm may be suffering from bias, variance problem or a bit of both.</p>
<p>High bias: If a learning algorithm is suffering from high bias, getting more training data will not(by itself) help much.</p>
<p>High variance: If a learning algorithm is suffering from high variance, getting more training data is likely to help.</p>
<p><img src="https://img-blog.csdnimg.cn/20210223193128828.png" alt="" /></p>
<p>Plotting learning curves like these can often help you figure out if your learning algorithm is suffering bias, or variance or even a little bit of both.</p>
<h3 id="107-deciding-what-to-do-next-revisited">10.7 Deciding What to Do Next (Revisited)</h3>
<p>Our original example:</p>
<ul>
<li>Get more training examples——help to fix high variance</li>
<li>Try smaller sets of features——help to fix high variance</li>
<li>Try getting additional features——fix high bias problems</li>
<li>Try adding polynomial features($x ^2_1,x ^2_2,x_1x_2,etc.$)——fix high bias problems</li>
<li>Try decreasing $\lambda$——fix high bias</li>
<li>Try increasing $\lambda$——fix high variance</li>
</ul>
<p>&ldquo;small&rdquo; neural network has few parameters and more likely to underfitting, the advantage of these small neural networks is that they are computationally cheaper.</p>
<p>&ldquo;large&rdquo; neural network with either more hidden units(a lot hidden unit in one layer) or with more hidden layers tend to have more parameters and therefore be more prone to overfitting. You can use regularization to address overfitting.</p>
<p><img src="https://img-blog.csdnimg.cn/20210223205550670.png" alt="" /></p>
<h2 id="11-machine-learning-system-design">11. Machine Learning System Design</h2>
<h3 id="111-prioritizing-what-to-work-on-spam-classification-example">11.1 prioritizing what to work on: Spam classification example</h3>
<p>In order to apply supervised learning, the first decision we must make is how do we want to represent x, that is the features of the email.</p>
<p>In practice, take most frequently occurring   words ( 10,000 to 50,000) in training set, rather than manually pick 100 words.</p>
<p>Spend your time to make it have low error</p>
<ul>
<li>
<p>Collect lots of data</p>
<ul>
<li>E.g. “honeypot” project.</li>
</ul>
</li>
<li>
<p>Develop sophisticated features based on email routing information (from email header).</p>
</li>
<li>
<p>Develop sophisticated features for message body, e.g. should “discount” and “discounts” be treated as the same word? How about “deal” and “Dealer”? Features about punctuation?</p>
</li>
<li>
<p>Develop sophisticated algorithm to detect misspellings (e.g. m0rtgage, med1cine, w4tches.)</p>
</li>
</ul>
<h3 id="112-error-analysis">11.2 Error Analysis</h3>
<h3 id="113-error-metrics-for-skewed-classes">11.3 Error Metrics for Skewed Classes</h3>
<p>If the number of positive examples is much smaller than the number of negative examples, we call it the case of skewed classes.</p>
<p>Facing this problem, we want to come up with a different error metric or a different evaluation metric. One such evaluation metric are what&rsquo;s called <font color=red>precision/recall.</font></p>
<table>
<thead>
<tr>
<th></th>
<th>1</th>
<th>0</th>
<th>←Actual clss</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>True Positive(TP)</td>
<td>False Positive(FP)</td>
<td>Precision</td>
</tr>
<tr>
<td>0</td>
<td>False Negative(FN)</td>
<td>True Negative(TN)</td>
<td></td>
</tr>
<tr>
<td>↑Predicted class</td>
<td>Recall</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>precision: TP/predicted positives = TP/(TP+FP)</p>
<p>recall: TP/actual positives = TP/(TP+FN)</p>
<h3 id="114-trading-off-precision-and-recall">11.4 Trading Off Precision and Recall</h3>
<p>For many applications, we&rsquo;ll want to somehow control the trade off between precision and recall.</p>
<p>If  you predict y=1 only if very confident by increase threshold, there will be higher precision and lower recall</p>
<p>If you avoid missing too many cases of cancer(FN) by decreasing threshold, there will be higher recall and lower precision</p>
<p><img src="https://img-blog.csdnimg.cn/20210224214902571.png" alt="" /></p>
<p>Average: $\frac{P+R}2$ is not a good method to evaluate</p>
<p>Fscore: $2\frac{PR}{P+R}$ is a better way</p>
<h3 id="115-data-for-machine-learning">11.5 Data For Machine Learning</h3>
<p><img src="https://img-blog.csdnimg.cn/20210224222912366.png" alt="" /></p>
<h2 id="12-support-vector-machines">12. Support Vector Machines</h2>
<p>SVM, compared with LR and NN, sometimes gives a cleaner and more powerful way of learning complex nonlinear functions.</p>
<h3 id="121-optimization-objective">12.1 Optimization Objective</h3>
<p>replace(simplify) the cost function of LR and make it easier to calculate</p>
<p>Cost function:</p>
<p><img src="https://img-blog.csdnimg.cn/20210224225524329.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20210224230323157.png" alt="" /></p>
<p>Finally unlike LR, the SVM doesn&rsquo;t output the probability. Instead what we have is this cost function, which we minimize to get parameters $\theta$. And what SVM does is just makes a prediction of y being equal 1 or 0 directly.</p>
<h3 id="122-large-margin-intuition">12.2 Large Margin Intuition</h3>
<p>Cost function:</p>
<p>if y=1, we want $\Theta^Tx&gt;=1$(not just &gt;= 0)</p>
<p>if y=0, we want $\Theta^Tx&lt;=-1$(not just &lt; 0)</p>
<p>This builds in an extra safety factor or safety margin factor into the SVM.</p>
<p>Let&rsquo;s see what happens or what the consequences of this are in the context of the SVM.</p>
<p>If C is very large, what we need to do is make first term equal to 0.</p>
<p>It turns out that when you solve this optimization problem, when you minimize this as a function of the parameters $\Theta$, you get a very interesting decision boundary.</p>
<p>In linearly separable case, the black line is a much better decision boundary than others. mathematically, this line has large distance. That distance is called the margin.</p>
<p><img src="https://img-blog.csdnimg.cn/20210224233738865.png" alt="" /></p>
<p>C like $\lambda$</p>
<p>If C is very large the decision boundary will be sensible to few outliers.</p>
<p>If C is not too large, SVM  also do fine and reasonable things even your data is not linearly separable.</p>
<h3 id="123-mathematics-behind-large-margin-classificationoptional">12.3 Mathematics Behind Large Margin Classification(optional)</h3>
<p>Math behind large margin classification</p>
<p>$u = \begin{bmatrix}u_1 \\ u_2\end{bmatrix} v=\begin{bmatrix}v_1 \\ v_2\end{bmatrix}$</p>
<p>Inner product = $u^Tv = u_1v_1+u_2v_2$</p>
<p>$|u| = \sqrt{u ^2_1+u ^2_2}$</p>
<p>Optimization objective = $\frac12(\Theta ^2_1+\Theta ^2_2) = \frac12(\sqrt{\Theta ^2_1+\Theta ^2_2}) ^2 = \frac12|\Theta| ^2$</p>
<p>s.t. $\Theta ^Tx ^{(i)}&gt;=1$ if $y ^{(i)}=1$</p>
<p>$\Theta ^Tx ^{(i)}&lt;=-1$ if $y ^{(i)}=0$</p>
<p>so $\Theta ^Tx ^{(i)} = \Theta_1x ^{i}_1+\Theta_2x ^{(i)}_2$</p>
<p><a href="https://blog.csdn.net/abc13526222160/article/details/83999933">The decision boundary and parameters $\Theta$ are 90 degree orthogonal</a>, we need a small range of parameters $\Theta$, that mean only when $p^{(i)}$ is big not small, that meet the condition $p^{(i)}\cdot{\left| \theta \right|}$ &gt;= 1 or &lt;= -1 since $|\Theta|$ is always positive.</p>
<p>The magnitude of the margin is exactly the values of $p ^{(1)}p ^{(2)}p ^{(3)}$ and so on. By making the margin large, SVM can end up with a smaller value for the norm of $\Theta$, which is what it is trying to do in the objective. And this is why SVM ends up with a large margin classifiers, because it is trying to maximize the norm of these $p ^{(i)}$ which is the distance from the training examples to the decision boundary.</p>
<p><img src="https://img-blog.csdnimg.cn/2021022514434148.png" alt="" /></p>
<h3 id="124-kernels-i">12.4 Kernels I</h3>
<p>$f_1=similarity(x,l ^{(1)})=e(-\frac{|x-l ^{(1)}| ^2}{2\sigma ^2})$<br />
$f_2=similarity(x,l ^{(2)})=e(-\frac{|x-l ^{(2)}| ^2}{2\sigma ^2})$<br />
$f_3=similarity(x,l ^{(3)})=e(-\frac{|x-l ^{(3)}| ^2}{2\sigma ^2})$</p>
<p>These particular choice of similarity function is called Gaussian kernel. But the way the terminology goes is that, in the abstract these different similarity functions are called kernels and we can have different similarity functions and the specific example I&rsquo;m giving here is called Gaussian kernel.</p>
<p>$If x\approx l ^{(1)} Then f_1 \approx e ^{-0} \approx 1$<br />
If x is far from $l ^{(1)}$ Then $f_1=e ^{\text{-large number} } \approx 0$</p>
<p><img src="https://img-blog.csdnimg.cn/20210225162638161.png" alt="" /></p>
<p>We predict 1 when $θ_0+θ_1f_1+θ_2f_2+θ_1f_3&gt;=0$</p>
<p>Let $\Theta_0=-0.5 \Theta_1=\Theta_2=1 \Theta_3=0$, and we can judge whether the point positive or not.</p>
<p>For the purple point $f1=1 f2=0 f3=0$ so $θ_0+θ_1f_1+θ_2f_2+θ_1f_3 = -0.5+1 = 0.5 &gt; 0$ . So this point is positive.</p>
<p><img src="https://img-blog.csdnimg.cn/20210225163430929.png" alt="" /></p>
<p>This is how with the definition of the landmarks and of the kernel function we can learn pretty complex non-linear decision boundary.</p>
<h3 id="125-kernels-ii">12.5 Kernels II</h3>
<p>Throw in some of the missing details and also, say a few words about how to use these ideas in practice. Such as, how to pertain to the bias variance trade-off in SVM.</p>
<p>Where to get landmarks $l ^{(1)}l ^{(2)}l ^{(3)}$? The idea here is we&rsquo;re gonna take the examples and for every training example, we are just put landmarks as exactly the same locations as the training examples.</p>
<p>Given an example x we are going to compute features as $f_1 f_2$ and so on. And these then give me a feature vector. $f = \begin{bmatrix}f_1 \\ f_2 \\ &hellip; \\ f_m \end{bmatrix}$ By convention, we can add an $f_0=1$</p>
<p>How to choose SVM parameters?:</p>
<p>C(=$\frac1\lambda$) Large C: Lower bias, high variance.</p>
<p>Small C: Higher bias, low variance.</p>
<p>$\sigma ^2$ in Gaussian kernel: Large $\sigma ^2$, features f vary more smoothly, higher bias, lower variance.</p>
<p>Small $\sigma ^2$: features f vary less smoothly. lower bias, higher variance.</p>
<h3 id="126-using-an-svm">12.6 Using An SVM</h3>
<p>kernel:</p>
<ul>
<li>No kernel(&ldquo;linear kernel&rdquo;) predict &ldquo;y=1&rdquo; if $\Theta ^Tx&gt;=0$(when n large and m small)</li>
<li>Gaussian kernel(when n small m large  non-linear boundary) [Note: Do perform feature scaling before using Gaussian kernel]
<ul>
<li>Polynomial Kernel</li>
<li>String kernel</li>
<li>chi-square kernel</li>
<li>histogram intersection kernel</li>
</ul>
</li>
</ul>
<p>Multiclass classification:</p>
<p>Many SVM packages already have built-in multi-class classification functionality.</p>
<p>Otherwise, use one-vs.-all method. (Train  K  SVMs, one to distinguish y=i from the rest, for i=1,2&hellip;k), get $\Theta ^{(1)}\Theta ^{(2)}&hellip;\Theta ^{(K)}$  Pick class i with largest ${\Theta ^{(i)}} ^Tx$.</p>
<p>LR vs. SVM:</p>
<p>If n is large(relative to m) use LR or SVM without a kernel(&ldquo;linear kernel&rdquo;)</p>
<p>If n is small, m is intermediate: use SVM with Gaussian kernel</p>
<p>If n is small, m is large: create/add more features, then use LR or SVM without a kernel</p>
<p>Neural network likely to work well for most if these settings, but may be slower to train.</p>
<h2 id="13-clustering">13. Clustering</h2>
<h3 id="131-unsupervised-learningintroduction">13.1 Unsupervised Learning——Introduction</h3>
<p>Our first unsupervised learning where we learn unlabeled data instead of labeled data.</p>
<h3 id="132-k-means-algorithm">13.2 K-Means Algorithm</h3>
<p>K-Means Algorithm by far the most popular most widely used clustering algorithm.</p>
<p>Input:</p>
<ul>
<li>K(number of clusters)</li>
<li>Training Set{$x ^{(1)} x ^{(2)},&hellip;x ^{(m)}$}</li>
</ul>
<p>STEP:</p>
<p>Randomly initialize K cluster centroids $\mu_1\mu_2&hellip;\mu_K$</p>
<p>Repeat:{</p>
<p>for i 1 to m: $c ^{(i)} = $index(for 1 to K) of cluster centroid closest to $x ^{(i)}$ <font color=blue>[cluster assignment step]</font></p>
<p>for k = 1 to K: $\mu_k$ = average(mean) of points assigned to cluster k <font color=blue>[move centroid step]</font></p>
<p>}</p>
<p>K-means for non-separated clusters</p>
<p>Like T-shirt sizing problem. You have many body shape and you need to decide how much clusters you need like S,M,L,XL. Then use algorithm to separate them.</p>
<h3 id="133-optimization-objective">13.3 Optimization Objective</h3>
<p>$\mu_{c ^{(i)} }$ = cluster centroid of cluster to which example $x ^{(i)}$ has been assigned</p>
<p>$x ^{(i)}$ is the training point , we want to minimize the sum of distance between points and cluster centroid</p>
<p><img src="https://img-blog.csdnimg.cn/20210226184719418.png" alt="" /></p>
<h3 id="134-random-initialization">13.4 Random Initialization</h3>
<p>Randomly pick K training examples.</p>
<p>Set $\mu_1,&hellip;\mu_k$ equal to these K examples.</p>
<p>Local optima:</p>
<p>initialize K-means lots of times and run K-means lots of times</p>
<p>for ( initialize, run K-means ,compute cost function)</p>
<p>pick clustering that gave lowest cost</p>
<h3 id="135-choosing-the-number-of-clusters">13.5 Choosing the Number of Clusters</h3>
<p>Elbow method:</p>
<p><img src="https://img-blog.csdnimg.cn/20210226204418658.png" alt="" /></p>
<p>Sometimes, you&rsquo;re running K-means to get clusters to use for some later/downstream purpose. Evaluate K=means based on a metric for how well it performs for that later purpose.</p>
<h2 id="14-dimensionality-reduction">14. Dimensionality Reduction</h2>
<h3 id="141-motivation-i-data-compression">14.1 Motivation I—— Data Compression</h3>
<p>Reduce data from 2D to 1D:</p>
<p><img src="https://img-blog.csdnimg.cn/20210302103154690.png" alt="" /></p>
<p>Reduce data from 3D to 2D:</p>
<p><img src="https://img-blog.csdnimg.cn/20210302103028233.png" alt="" /></p>
<p>All these data maybe all of this data maybe lies roughly  on the plane. And what we can do with dimensionality reduction is take all of this data and project the data down onto a two dimensional plane.</p>
<h3 id="142-motivation-iivisualization">14.2 Motivation II——Visualization</h3>
<p>Application of dimensionality reduction——visualize the data. For a lot of machine learning applications, it helps us to develop effective learning algorithms. if we can understand our data better, there is some way of visualizing the data better,  and so, dimensionality reduction offers us another useful tool to do so.</p>
<p>If we can use z1 an z2 to summarizes 50 numbers, then plot these countries in R2 and the understand this sort of features of different countries will be better. What you can do is reduce the data from 50D to 2D. z1 and z2 doesn&rsquo;t astride a physical meaning.</p>
<p><img src="https://img-blog.csdnimg.cn/20210302105411852.png" alt="" /></p>
<h3 id="143-principal-component-analysis-problem-formulation">14.3 Principal Component Analysis Problem Formulation</h3>
<p>Let try to formulate precisely exactly what we would like PCA to do.</p>
<p>PCA tries to find a lower-dimensional surface onto which to project the data.</p>
<p>Reduce from 2D to 1D: find a direction onto thich to project the data so as to minimize the projection error.</p>
<p>Reduce from nD to kD:  find k vectors onto which to project the data  so as to minimize the projection error. (3D to 2D  together vectors define a plain or 2D surface)</p>
<p>PCA&amp;LR</p>
<p><img src="https://img-blog.csdnimg.cn/20210302145354439.png" alt="" /></p>
<p>LR fitting a straight line so as to minimize the squared error between a point and the straight line. Notice we drawing distance vertically(point and the point on the line). PCA tries to minimize the shortest orthogonal distances( point and line)</p>
<h3 id="144-principal-component-analysis-algorithm">14.4 Principal Component Analysis Algorithm</h3>
<p>Before applying PCA, there is a data pre-processing step which you should always do.</p>
<p>Preprocessing(features scaling/mean normalization): First compute the mean of  each feature $\mu_j = \frac1m\sum ^m_{i=1}x_j ^{(i)}$ and replace each feature $x_j = x_j-\mu_j$.</p>
<p>Compute covariance matrix: $\Sigma = \frac1m\sum ^n_{i=1}(x ^{(i)})(x ^{(i)}) ^T$</p>
<p>Compute eigenvectors: [U,S,V] = svd(Sigma) <font color=red>[svd:singular value decomposition]</font></p>
<p>S is a Diagonal matrix.</p>
<p>U is a NxN dimensional vector, reduce to k dimensional vector</p>
<p>$z ^{(i)}=U ^T_{reduce}*x ^{(i)}$</p>
<p><img src="https://img-blog.csdnimg.cn/2021030220403511.png" alt="" /></p>
<h3 id="145-choosing-the-number-of-principal-components">14.5 Choosing The Number Of Principal Components</h3>
<p>Choosing k(number of principle components)</p>
<p>Average squared projection error:</p>
<p>Total variation in the data:</p>
<p>Typically, choose k to be smallest value so that</p>
<p>$\frac{\text{Average squared projection error} } {\text{Total variation in the data} }&lt;=0.01$ (99% of variance is retained)</p>
<p>Run SVD once and you get Diagonal matrix, then calculate k.</p>
<p>$\frac {\Sigma ^k_{i=1}s_{ii} }{\Sigma ^n_{i=1}s_{ii}}\geq0.99$</p>
<p><img src="https://img-blog.csdnimg.cn/20210303142142409.png" alt="" /></p>
<h3 id="146-reconstruction-from-compressed-representation">14.6 Reconstruction from Compressed Representation</h3>
<p><img src="https://img-blog.csdnimg.cn/20210303142831633.png" alt="" /></p>
<h3 id="147-advice-for-applying-pca">14.7 Advice for Applying PCA</h3>
<p>Speedup supervised learning:</p>
<p>100x100 pictures</p>
<ol>
<li>Apply PCA and reduce to 1000 dimensional features vectors.</li>
<li>Feed new training set to a learning algorithm.</li>
<li>For example X, map it through the same mapping that was found by PCA to get corresponding Z and fed to hypothesis and make a prediction.</li>
</ol>
<p><img src="https://img-blog.csdnimg.cn/20210303171412201.png" alt="" /></p>
<p>Application of PCA</p>
<ul>
<li>Compression(Choose K by percentage of variance retained)
<ul>
<li>Reduce memory/disk needed to store data</li>
<li>Speed up learning algorithm</li>
</ul>
</li>
<li>Visualization(k=2 or k=3)</li>
</ul>
<p>Bad use of PCA: To prevent over-fitting</p>
<p>Use $z ^{(i)}$ instead of $x ^{(i)}$ to reduce the number of features to k &lt; n. (fewer features, less likely to over-fit). Actually isn&rsquo;t a good way to address over-fitting. Use regularization instead. Why? PCA throws away some information, reduce dimension of your data without knowing what the values of y is. It might also throw away some valuable information. Use regularization will often gives you at least as good a method for preventing over-fitting.</p>
<p>Often at very start of a project, someone will just write out a project plan and use PCA inside. How about doing the whole thing without using PCA? Before implementing PCA, first try running whatever you want to do with original/raw data $x ^{(i)}$. Only if that doesn&rsquo;t do what you want, then implement PCA and consider using $z ^{(i)}$.</p>
<h2 id="15-anomaly-detection">15. Anomaly Detection</h2>
<p>Anomaly Detection is mainly for unsupervised problem, that there&rsquo;s some aspects of it that are also very similar to sort of the supervised learning problem.</p>
<h3 id="151-problem-motivation">15.1 Problem Motivation</h3>
<p>Density estimation:</p>
<p>dataset: {$x ^{(1)},x ^{(2)},x ^{(3)},&hellip;.x ^{(m)}$}</p>
<p>$if \quad p(x) \begin{cases} &lt; \varepsilon &amp; anomaly \\ &gt; =\varepsilon &amp; normal \end{cases}$</p>
<p>Anomaly detection example:</p>
<p><img src="https://img-blog.csdnimg.cn/20210308102332898.png" alt="" /></p>
<h3 id="152-gaussian-distribution">15.2 Gaussian Distribution</h3>
<p>Gaussian distribution = Normal distribution</p>
<p>$x \sim N(\mu, \sigma ^2)$</p>
<p>$p(x,\mu,\sigma ^2)=\frac{1}{\sqrt{2\pi}\sigma}\exp\left(-\frac{(x-\mu) ^2}{2\sigma ^2}\right)$</p>
<p>$\mu=\frac{1}{m}\sum\limits_{i=1} ^{m}x ^{(i)}$</p>
<p>$\sigma ^2=\frac{1}{m}\sum\limits_{i=1} ^{m}(x ^{(i)}-\mu) ^2$</p>
<p><img src="https://img-blog.csdnimg.cn/20210308103214513.png" alt="" /></p>
<h3 id="153-algorithm">15.3 Algorithm</h3>
<p>Apply Gaussian distribution to develop an anomaly detection algorithm.</p>
<p>Given dataset $x ^{(1)},x ^{(2)},&hellip;,x ^{(m)}$, which is distributed according to a Gaussian distribution. So $\mu_j=\frac1m\sum\limits_{i=1} ^mx_j ^{(i)}$ and $\sigma_j ^2=\frac1m\sum\limits_{i=1} ^m(x_j ^{(i)}-\mu_j) ^2$. These data may be vectorized versions.</p>
<p>Compute p(x).</p>
<p>$p(x)=\prod\limits_{j=1} ^np(x_j;\mu_j,\sigma_j ^2)=\prod\limits_{j=1} ^1\frac{1}{\sqrt{2\pi}\sigma_j}exp(-\frac{(x_j-\mu_j) ^2}{2\sigma_j ^2})$. It is anomaly if $p(x) &lt; \epsilon$.</p>
<p><img src="https://img-blog.csdnimg.cn/2021031115570018.png" alt="" /></p>
<p>The height of this 3-D surface is p(x). To check a point is anomaly or not, we set some very small  value for epsilon, and then compute p(x) of the point. If p(x) greater than or equal to epsilon, then we think it is not an anomaly. But if p(x) is smaller then epsilon, that is indeed an anomaly.</p>
<h3 id="154-developing-and-evaluating-an-anomaly-detection-system">15.4 Developing and Evaluating an Anomaly Detection System</h3>
<p>How to develop a specific anomaly detection algorithm<br />
How to evaluate an anomaly detection algorithm</p>
<p>Assume we have some labeled data, of anomalous and non-anomalous examples.</p>
<p>And we are going to define a cross validation set and a test set, with which to evaluate a particular anomaly detection algorithm.</p>
<p>Example:</p>
<p>10000 good engines and 20 flawed engines</p>
<p>Training set: 6000 good engines<br />
CV: 2000 good engines(y=0) 10 anomalous(y=1)<br />
Test: 2000 good engines(y=0) 10 anomalous(y=1)</p>
<p>Get training set and fit p(x)</p>
<p>Evaluate: It is a very skewed data set, then predicting y equals 0 all the time will have very high classification accuracy. Instead, we should use evaluation metrics like computing the Precision/Recall or do things like compute the F1 score, which is a single real-number way of summarizing the precision and the recall numbers.</p>
<p>Use cross validation set to choose parameter $\epsilon$ which maximizes F1 score or the otherwise does well on your cross validation sets.</p>
<h3 id="155-anomaly-detection-vs-supervised-learning">15.5 Anomaly Detection vs. Supervised Learning</h3>
<p>If we have this labeled data, we have some examples that are known to be anomalies and some that are known not to be not anomalies, why don&rsquo;t we just use a supervised learning algorithm, so why don&rsquo;t we just use logistic regression or a neural network to try to learn directly from our labeled data, to predict whether y equals one or y equals zero?</p>
<table>
<thead>
<tr>
<th>Anomaly Detection</th>
<th>Supervised Learning</th>
</tr>
</thead>
<tbody>
<tr>
<td>Very small number of positive examples. Large number of negative examples.</td>
<td>Large number of positive and negative examples simultaneously.</td>
</tr>
<tr>
<td>Many different &ldquo;types&rdquo; of anomalies. Hard for any algorithm to learn from positive examples what the anomalies look like.</td>
<td>Enough positive examples for algorithm to get a sense of what positive examples are like.</td>
</tr>
<tr>
<td>Future anomalies mat look nothing like any of the anomalous examples we&rsquo;ve seen so far.</td>
<td>Future positive examples likely to be similar to ones in training set.</td>
</tr>
<tr>
<td>Examples: Fraud detection, Manufacturing(aircraft engines), Monitoring machines in a data center</td>
<td>Examples: Email spam problem, Weather prediction, Cancer classification</td>
</tr>
</tbody>
</table>
<h3 id="156-choosing-what-features-to-use">15.6 Choosing What Features to Use</h3>
<p>You have seen the anomaly detection algorithm and we&rsquo;ve talked about how to evaluate an anomaly detection algorithm.</p>
<p>It turns out that when you&rsquo;re applying anomaly detection, one of the things that has a huge effect on how well it does, is what features you use, and what features you choose, to give the anomaly detection algorithm.</p>
<p>Transformations of the data in order to make it look more Gaussian might work a bit better.</p>
<p>We can use log function($x = log(x+c), c&gt;=0$) to transform the data, function in python <code>np.log1p</code> = <code>log(x+1)</code></p>
<p>Error analysis for anomaly detection</p>
<p>run on CV and look at the examples it gets wrong and come up with extra features to help algorithm.</p>
<p><img src="https://img-blog.csdnimg.cn/20210311174907968.png" alt="" /></p>
<p>Monitoring computers in a data center</p>
<p>Choose features that might take on unusually large or small values on the event of an anomaly.</p>
<p>$x_1$ =  memory use of computer<br />
$x_2$ = number of disk accesses/sec<br />
$x_3$ = CPU load<br />
$x_4$ = network traffic</p>
<p>to check infinite loop, we may need a new feature $x_5 = \frac{x_3}{x_4}$. this may take on a unusually large value if one of the machines has a very large CPU load but not that much network traffic. So that will help your anomaly detection capture, a certain type of anomaly.</p>
<h3 id="157-multivariate-gaussian-distribution-optional">15.7 Multivariate Gaussian Distribution (Optional)</h3>
<h3 id="158-anomaly-detection-using-the-multivariate-gaussian-distribution-optional">15.8 Anomaly Detection using the Multivariate Gaussian Distribution (Optional)</h3>
<h2 id="16-recommender-systems">16. Recommender Systems</h2>
<h3 id="161-problem-formulation">16.1 Problem Formulation</h3>
<p>Recommender systems is an important application of machine learning.</p>
<p>Through recommender systems, will be able to go a little bit into this idea of learning the features.</p>
<p>Recommender systems look at what books you may have purchased in the past, or what movies you have rated.</p>
<p><img src="https://img-blog.csdnimg.cn/20210305195132636.png" alt="" /></p>
<p>And so, our job in developing a recommender system is to come up with a learning algorithm that  can automatically go fill in these missing values.</p>
<h3 id="162-content-based-recommendations">16.2 Content Based Recommendations</h3>
<p>If we have features like these then each movie can be represented with a feature vector.</p>
<p>We could treat predicting the ratings of each user as a separate linear regression problem.</p>
<p>For each user j, learn a parameter $\Theta ^{(j)} \in \mathbb{R} ^3$. Predict user j as rating movie i with $(\Theta ^{(j)} ) ^Tx ^{(i)}$ stars.</p>
<p><img src="https://img-blog.csdnimg.cn/20210305222337123.png" alt="" /></p>
<p><img src="https://img-blog.csdnimg.cn/20210305224727251.png" alt="" /></p>
<h3 id="163-collaborative-filtering">16.3 Collaborative Filtering</h3>
<p>we&rsquo;re talking a recommender system that&rsquo;s called collaborative filtering, which start to learn for itself what features to use.</p>
<p>Know $\Theta$ in advance, we can get the features X since $(\Theta ^{(j)} ) ^Tx ^{(i)} = movie ratings$.</p>
<p><img src="https://img-blog.csdnimg.cn/20210305225012483.png" alt="" /></p>
<h3 id="164-collaborative-filtering-algorithm">16.4 Collaborative Filtering Algorithm</h3>
<p><img src="https://img-blog.csdnimg.cn/2021030523055648.png" alt="" /></p>
<ol>
<li>Initialize $x ^{(1)}&hellip;x ^{(n_m)},\Theta ^{(1)}&hellip;\Theta ^{(n_m)}$ to small random values.</li>
<li>Minimize $J(x ^{(1)}&hellip;x ^{(n_m)},\Theta ^{(1)}&hellip;\Theta ^{(n_m)})$ using gradient descent(or an advanced optimization algorithm).</li>
<li>For a user with parameters $\Theta$ and a movie with(learned) features x, predict a star rating of $\Theta ^Tx$.</li>
</ol>
<h3 id="165-vectorizationlow-rank-matrix-factorization">16.5 Vectorization——Low Rank Matrix Factorization</h3>
<p>Like matrix multiplication</p>
<p><img src="https://img-blog.csdnimg.cn/20210305231658378.png" alt="" /></p>
<p>Finding related movies:</p>
<p>For each product i, we learn a feature vector $x ^{(i)}$.</p>
<p>small $|x ^{(i)}-x ^{(j)}|$ ——&gt; movie j and movie i are &ldquo;similar&rdquo;.</p>
<h3 id="166-implementation-detailmean-normalization">16.6 Implementation Detail——Mean Normalization</h3>
<p>If user Eve hasn&rsquo;t rated any movies. The only Influential part is the last part. We want to choose vector theta 5 so that the last regularization term is as small as possible. We would end up getting a $\Theta$ that is all 0.</p>
<p>The idea of mean normalization will let us fix this problem.</p>
<p>I&rsquo;m going to compute the average rating($\mu$) that each movie obtained. All the movie ratings subtract off the mean rating.</p>
<p>So, what I&rsquo;m doing is just normalizing each movie to have an average rating of zero.</p>
<p>Now use this set of ratings with my collaborative filtering algorithm. Our last prediction should be $(\theta ^{(j)})^T x ^{(i)}+\mu_i$. This mean user Eve will get the average rating.</p>
<p><img src="https://img-blog.csdnimg.cn/20210305234126857.png" alt="" /></p>
<h2 id="17-large-scale-machine-learning">17. Large Scale Machine Learning</h2>
<h3 id="171-learning-with-large-datasets">17.1 Learning With Large Datasets</h3>
<p>Before investing the effort into actually developing and the software needed to train these massive models is often a good sanity check, if training on just a thousand examples might do just as well.</p>
<p>If we have a high variance model, we may need large datasets.<br />
If we have a high bias model, large datasets may don&rsquo;t help.</p>
<p>So in large-scale machine learning, we like to come up with computationally reasonable ways, or computationally efficient ways, to deal with very big data sets.</p>
<h3 id="172-stochastic-gradient-descent">17.2 Stochastic Gradient Descent</h3>
<p>we&rsquo;ll talk about a modification to the basic gradient descent algorithm called Stochastic gradient descent, which will allow us to scale these algorithms to much bigger training sets.</p>
<p>If dataset is large, it&rsquo;s gonna take a long time in order to get the algorithm to converge.(Batch gradient descent)</p>
<p>In contrast to Batch gradient descent, what we are going to do is come up with a different algorithm that doesn&rsquo;t need to look at all the training examples in every single iteration, but that needs to look at only a single training example in one iteration.(Stochastic gradient descent)</p>
<p><img src="https://img-blog.csdnimg.cn/20210306235433949.png" alt="" /></p>
<h3 id="173-mini-batch-gradient-descent">17.3 Mini-Batch Gradient Descent</h3>
<p>Batch gradient descent: Use all m examples in each iteration<br />
Stochastic gradient descent: Use 1 example in each iteration<br />
Mini-batch gradient descent: Use b examples in each iteration</p>
<p>b = mini-batch size  usually b=10(2-100)</p>
<p><img src="https://img-blog.csdnimg.cn/20210307134950855.png" alt="" /></p>
<p>Why do we want to look at b examples at a time rather than look at just a single example at a time as the Stochastic gradient descent?</p>
<p>The answer is in vectorization.</p>
<p>Mini-batch gradient descent is likely to outperform Stochastic gradient descent only if you have a good vectorized implementation. In that case, the sum over 10 examples can be performed in a more vectorized way which will allow you to partially parallelize your computation over the ten examples.</p>
<h3 id="174-stochastic-gradient-descent-convergence">17.4 Stochastic Gradient Descent Convergence</h3>
<p>By using a smaller learning rate, you&rsquo;ll end up with smaller oscillations.</p>
<p>To get a smoother curve, you need to increase the number of examples.</p>
<p>When curve looks like it&rsquo;s increasing, what you really should do is use a smaller value of the learning rate alpha.</p>
<p>If you want stochastic gradient descent to actually converge to the global minimum, there&rsquo;s one thing which you can do which is you can slowly decrease the learning rate alpha over time.$\alpha = \frac{const1}{iterationNumber + const2}$</p>
<h3 id="175-online-learning">17.5 Online Learning</h3>
<p>For a continuous stream of data from online website.</p>
<p>When a user come in the website, we get a example (x,y) and learn from that and discard it.</p>
<p>This sort of online learning algorithm can also adapt to changing user preferences and kind of keep track of what your changing population of users may be willing to pay for.</p>
<p>The problem of learning the predicted click-through rate, the predicted CTR.</p>
<p><img src="https://img-blog.csdnimg.cn/20210307165155109.png" alt="" /></p>
<h3 id="176-map-reduce-and-data-parallelism">17.6 Map Reduce and Data Parallelism</h3>
<p>Assign tasks to multiple computers on average then centralized master server combine results together.</p>
<p>On a single multi-core computer, you can split the training sets into pieces and send the training set to different cores within a single box.</p>
<p>we talked about the MapReduce approach to parallelizing machine learning by taking a data and spreading them across many computers in the data center. Although these ideas are critical to parallelizing across multiple cores within a single computer as well.</p>
<h2 id="18-application-example-photo-ocr">18. Application Example: Photo OCR</h2>
<h3 id="181-problem-description-and-pipeline">18.1 Problem Description and Pipeline</h3>
<p>Photo OCR stands for Photo Optical Character Recognition. The photo OCR problem focuses on how to get computers to read the text to the purest in images that we take.</p>
<p>First, given the picture it has to look through the image and detect where there is text in the picture.</p>
<p>Read the text in those regions.</p>
<p>Doing OCR from photographs today is still a very difficult machine learning problem.</p>
<p>Photo OCR pipeline:</p>
<ol>
<li>Text detection</li>
<li>Character segmentation</li>
<li>Character classification</li>
</ol>
<p><img src="https://img-blog.csdnimg.cn/20210304195257378.png" alt="" /></p>
<h3 id="182-sliding-windows">18.2 Sliding Windows</h3>
<p>Pedestrian detection:</p>
<p>Supervised learning for pedestrian detection(sliding windows classifier)</p>
<p>shift the rectangle over each time is a parameter called the step size(also called the slide parameter)</p>
<p>we can choose a big rectangle and resize to the smaller one and get it detected by classifier.</p>
<p>Text detection:</p>
<ol>
<li>use classifier to get the possibility of text</li>
<li>apply expansion operator and expand white pixel</li>
<li>rule out strange rectangles and draw rectangles around text</li>
</ol>
<p>How do we segment out the individual characters in this image?</p>
<p>use a supervised learning to decide if there is split between two characters</p>
<h3 id="183-getting-lots-of-data-and-artificial-data">18.3 Getting Lots of Data and Artificial Data</h3>
<p>One of the most reliable ways to get a high performance machine learning system is to take a low bias learning algorithm and to train it on a massive training set. But where did you get so much training data from?</p>
<p>Artificial data synthesis [creating new data from scratch, amplify that training set or turn to a large one]</p>
<p>Create new: downloaded font</p>
<p>Amplify: artificial stretching or artificial distortions</p>
<p>Discussion on getting more data:</p>
<ol>
<li>Make sure you have a low bias classifier before expending the effort. (Plot learning curves). E.g. keep increasing the number of features/number of hidden units in neural network until you have a low bias classifier.</li>
<li>“How much work would it be to get 10x as much data as we currently have?”</li>
</ol>
<ul>
<li>Artificial data synthesis</li>
<li>Collect/label it yourself</li>
<li>Crowd source(E.g. Amazon Mechanical Turk)</li>
</ul>
<h3 id="184-ceiling-analysiswhat-part-of-the-pipeline-to-work-on-next">18.4 Ceiling Analysis——What Part of the Pipeline to Work on Next</h3>
<ol>
<li>
<p>go to my test set and just give it the correct answers for the text detection part of the pipeline.</p>
</li>
<li>
<p>And now going to give the correct text detection output and give the correct character segmentation outputs and manually label the correct segment orientations of text into individual characters.</p>
</li>
</ol>
<p>Now, the nice thing about having done this analysis analysis is we can now understand what is the upside potential for improving each of these components.</p>
<p>text detection——17 percent performance gain<br />
character segmentation——1 percent performance gain<br />
character recognition——10 percent performance gain</p>
<p>ceiling analysis gives the upside potential</p>
<p><img src="https://img-blog.csdnimg.cn/20210305175103438.png" alt="" /></p>
<h2 id="19-conclusion">19. Conclusion</h2>
<h3 id="191-summary-and-thank-you">19.1 Summary and Thank You</h3>

    </article>
    
    
<script defer src="/js/clipboard.min.c168d3a04c45a631be76437054619a4a3b30107960cb9730be96012fef5762b0.js"></script>

<script defer src="/js/helper/prev.min.js"></script>

<script defer src="/js/helper/prop.min.js"></script>
<script>
  'use strict';
  document.addEventListener('DOMContentLoaded', function () {
    
    var clipInit = false;
    var preChromaElem = document.querySelectorAll('pre.chroma');
    var langCodeElem = document.querySelectorAll('.language-code');
    var dollarCodeElem = document.querySelectorAll('div.language-\\$');
    var gtCodeElem = document.querySelectorAll('div.language-\\>');

    var makeClipboard = function(elem) {
      var code = elem,
          text = elem.textContent;
        
      if (text.length > 15) {
        if (!clipInit) {
          var text, clip = new ClipboardJS('.copy-to-clipboard', {
            text: function (trigger) {
              var codeElem = prev(trigger).querySelectorAll('code');
              if (codeElem.length > 1) {
                text = prev(trigger).querySelector('code[class^="language-"]').textContent;
              } else {
                text = prev(trigger).querySelector('code').textContent;
              }

              return text.replace(/^\$\s/gm, '');
            }
          });

          var inPre;
          clip.on('success', function (e) {
            e.clearSelection();
            inPre = prop(e.trigger.parentNode, 'tagName') == 'PRE';
            e.trigger.setAttribute('aria-label', 'Copied to clipboard!');
            e.trigger.classList.add('tooltipped');
            e.trigger.classList.add('tooltipped-w');
          });

          clip.on('error', function (e) {
            inPre = prop(e.trigger.parentNode, 'tagName') == 'PRE';
            e.trigger.setAttribute('aria-label', e.action.toString());
            e.trigger.classList.add('tooltipped');
            e.trigger.classList.add('tooltipped-w');
          });

          clipInit = true;
        }

        var notAllowedClass = ['language-mermaid', 'language-viz', 'language-wave', 'language-chart', 'language-msc', 'language-flowchart'];
        var isNotAllowedIncluded = false;
        var curClassName = code.getAttribute('class');

        for (var i = 0; i < notAllowedClass.length; i++) {
          if (curClassName && curClassName.startsWith(notAllowedClass[i])) {
            isNotAllowedIncluded = true;
            break;
          }
        }

        if (!isNotAllowedIncluded) {
          if (curClassName) {
            var newClipboardElem = document.createElement('span');
            newClipboardElem.setAttribute('class', 'copy-to-clipboard');
            newClipboardElem.setAttribute('title', 'Copy to clipboard');
            elem.parentNode.parentNode.insertBefore(newClipboardElem, elem.parentNode.nextElementSibling);
          }
        }
      }
    }

    var makeSymbolClipboard = function(elem) {
      var clipboardSpan = document.createElement('span');
      clipboardSpan.setAttribute('class', 'copy-to-clipboard');
      clipboardSpan.setAttribute('title', 'Copy to clipboard');
      elem.parentNode.parentNode.insertBefore(clipboardSpan, elem.parentNode.nextElementSibling);
    }

    preChromaElem ? 
    preChromaElem.forEach(function(elem) {
      elem.querySelectorAll('code').forEach(function(codeElem) {
        makeClipboard(codeElem);
      });
    }) : null;
    
    langCodeElem ? 
    langCodeElem.forEach(function(elem) {
      elem.querySelectorAll('code').forEach(function (codeElem) {
        makeClipboard(codeElem);
      });
    }) : null;

    dollarCodeElem ? 
    dollarCodeElem.forEach(function(elem) {
      elem.querySelectorAll('code').forEach(function (codeElem) {
        makeSymbolClipboard(codeElem);
      });
    }) : null;

    gtCodeElem ?
    gtCodeElem.forEach(function(elem) {
      elem.querySelectorAll('code').forEach(function (codeElem) {
        makeSymbolClipboard(codeElem);
      });
    }) : null;
    
  });
</script>
    <script>
  'use strict';
  
  function wrap(el, wrapper) {
    el.parentNode.insertBefore(wrapper, el);
    wrapper.appendChild(el);
  }

  (function () {
    var singleContentsElem = document.querySelector('.single__contents');
    singleContentsElem ? 
    singleContentsElem.querySelectorAll('pre > code').forEach(function(elem) {
      var dataLang = elem.getAttribute('data-lang');
      var dataLangWrapper = document.createElement('div');
      var code = null;
      var codeTitle = null;

      if (dataLang && dataLang.includes(':')) {
        code = dataLang.split(':')[0];
        codeTitle = dataLang.split(':')[1];

        dataLangWrapper.className = 'language-' + code;
        dataLangWrapper.setAttribute('data-lang', codeTitle);

        elem.className = 'language-' + code;
        elem.setAttribute('data-lang', codeTitle);
        elem.setAttribute('id', codeTitle);
      } else if (!dataLang) {
        dataLangWrapper.setAttribute('data-lang', 'Code');
        dataLangWrapper.className = 'language-code';
      }

      if (!dataLang || codeTitle) {
        wrap(elem.parentNode, dataLangWrapper);
      }

    }) : null;
  })();

  var langCodeElem = document.querySelectorAll('.language-code');
  langCodeElem ? langCodeElem.forEach(function (elem) {
    var newElem = document.createElement('span');
    newElem.className = 'copy-to-clipboard';
    newElem.setAttribute('title', 'Copy to clipboard');
    elem.append(newElem);
  }) : null;
  

  

  
  var dollarCodeElem = document.querySelectorAll('div.language-\\$');
  var gtCodeElem = document.querySelectorAll('div.language-\\>');

  dollarCodeElem ?
  dollarCodeElem.forEach(function(elem) {
    var lnts = elem.parentNode.parentNode ? elem.parentNode.parentNode.querySelectorAll('.lnt') : null;
    lnts ? 
    lnts.forEach(function(lnt) {
      lnt.innerHTML = '$<br/>';
    }) : null;
  }) : null;

  gtCodeElem ?
  gtCodeElem.forEach(function(elem) {
    var lnts = elem.parentNode.parentNode ? elem.parentNode.parentNode.querySelectorAll('.lnt') : null;
    lnts ? 
    lnts.forEach(function(lnt) {
      lnt.innerHTML = '><br/>';
    }) : null;
  }) : null;
  
</script>
    
<div class="donation">
  <div class="donation__message">
    Share on
  </div>
  <div class="donation__icons">
    
    
    
      
    
      
    
  </div>
</div>


    
    
<div class="whoami__gutter"></div>
<hr class="hr-slash whoami-hr"/>
<section class="whoami">
  <div class="whoami__image-wrapper">
    
    
      
        <img data-src="/images/whoami/avatar.jpg" src="data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='none' d='M0 0h24v24H0V0z'/%3E%3Cpath fill='%23aaa' d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V6c0-.55.45-1 1-1h12c.55 0 1 .45 1 1v12c0 .55-.45 1-1 1zm-4.44-6.19l-2.35 3.02-1.56-1.88c-.2-.25-.58-.24-.78.01l-1.74 2.23c-.26.33-.02.81.39.81h8.98c.41 0 .65-.47.4-.8l-2.55-3.39c-.19-.26-.59-.26-.79 0z'/%3E%3C/svg%3E" alt="ruokeqx" class="lazyload whoami__image"/>
      
    
  </div>
  <div class="whoami__contents">
    <div class="whoami__written-by">
      WRITTEN BY
    </div>
    <div class="whoami__title">
      
        ruokeqx
      
    </div>
    <div class="whoami__desc">
      
        
      
    </div>
    <div class="whoami__social">
      
      
      
      
      
      
      
      
      <a href="ruokeqx@163.com" title="email" aria-label="email">
        <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="currentColor" d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm-.4 4.25l-7.07 4.42c-.32.2-.74.2-1.06 0L4.4 8.25c-.25-.16-.4-.43-.4-.72 0-.67.73-1.07 1.3-.72L12 11l6.7-4.19c.57-.35 1.3.05 1.3.72 0 .29-.15.56-.4.72z"/></svg>
      </a>
      
      
      
      
      
      
      
      <a href="https://github.com/ruokeqx" title="github" aria-label="github">
        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="25" height="25" viewBox="0 0 24 24" version="1.1">
<g id="surface3680">
<path fill="currentColor" d="M 10.898438 2.101562 C 6.300781 2.601562 2.601562 6.300781 2.101562 10.800781 C 1.601562 15.5 4.300781 19.699219 8.398438 21.300781 C 8.699219 21.398438 9 21.199219 9 20.800781 L 9 19.199219 C 9 19.199219 8.601562 19.300781 8.101562 19.300781 C 6.699219 19.300781 6.101562 18.101562 6 17.398438 C 5.898438 17 5.699219 16.699219 5.398438 16.398438 C 5.101562 16.300781 5 16.300781 5 16.199219 C 5 16 5.300781 16 5.398438 16 C 6 16 6.5 16.699219 6.699219 17 C 7.199219 17.800781 7.800781 18 8.101562 18 C 8.5 18 8.800781 17.898438 9 17.800781 C 9.101562 17.101562 9.398438 16.398438 10 16 C 7.699219 15.5 6 14.199219 6 12 C 6 10.898438 6.5 9.800781 7.199219 9 C 7.101562 8.800781 7 8.300781 7 7.601562 C 7 7.199219 7 6.601562 7.300781 6 C 7.300781 6 8.699219 6 10.101562 7.300781 C 10.601562 7.101562 11.300781 7 12 7 C 12.699219 7 13.398438 7.101562 14 7.300781 C 15.300781 6 16.800781 6 16.800781 6 C 17 6.601562 17 7.199219 17 7.601562 C 17 8.398438 16.898438 8.800781 16.800781 9 C 17.5 9.800781 18 10.800781 18 12 C 18 14.199219 16.300781 15.5 14 16 C 14.601562 16.5 15 17.398438 15 18.300781 L 15 20.898438 C 15 21.199219 15.300781 21.5 15.699219 21.398438 C 19.398438 19.898438 22 16.300781 22 12.101562 C 22 6.101562 16.898438 1.398438 10.898438 2.101562 Z M 10.898438 2.101562 "/>
</g>
</svg>

      </a>
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    </div>
  </div>
</section>
<hr class="hr-slash whoami-hr" />


    <section class="related">
    
    
  </section>
    <div class="grow"></div>
<nav class="pagination-single">
  
    
      <a href="https://ruokeqx.gitee.io/posts/2020ctfwp/" class="pagination-single__left">
        <div class="pagination-single__icon">
          <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="currentColor" d="M19 11H7.83l4.88-4.88c.39-.39.39-1.03 0-1.42-.39-.39-1.02-.39-1.41 0l-6.59 6.59c-.39.39-.39 1.02 0 1.41l6.59 6.59c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L7.83 13H19c.55 0 1-.45 1-1s-.45-1-1-1z"/></svg>
        </div>
        <div class="pagination-single__left-title">2020CTF WP</div>      
      </a>
    
    <div class="grow"></div>
    
      <a href="https://ruokeqx.gitee.io/posts/deep-learning-andrew-ng-stanford/" class="pagination-single__right">      
        <div class="pagination-single__right-title">CS230 Deep Learning——Andrew Ng——Stanford</div>
        <div class="pagination-single__icon">
          <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="currentColor" d="M5 13h11.17l-4.88 4.88c-.39.39-.39 1.03 0 1.42.39.39 1.02.39 1.41 0l6.59-6.59c.39-.39.39-1.02 0-1.41l-6.58-6.6c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.02 0 1.41L16.17 11H5c-.55 0-1 .45-1 1s.45 1 1 1z"/></svg>
        </div>
      </a>
    
  
</nav>
    
    <div class="modal micromodal-slide" id="modal" aria-hidden="true">
  <div class="modal__overlay" tabindex="-1" data-micromodal-close>
    <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
      
      <div class="modal__content" id="modal-content">
        <div id="mySwipe" class="swipe">
          <div class="swipe-wrap">
          </div>
        </div>
      </div>

      <span class="modal__items">
        
        <span class="modal__header">
          <div class="modal__paging" title="Page Info" aria-label="Current Page">
          </div>
          <div class="modal__icon modal__toolbar modal__toolbar--close" title="Close" aria-label="Close Button" data-micromodal-close>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 26" width="25" height="25"><path fill="currentColor" d="M 21.734375 19.640625 L 19.636719 21.734375 C 19.253906 22.121094 18.628906 22.121094 18.242188 21.734375 L 13 16.496094 L 7.761719 21.734375 C 7.375 22.121094 6.746094 22.121094 6.363281 21.734375 L 4.265625 19.640625 C 3.878906 19.253906 3.878906 18.628906 4.265625 18.242188 L 9.503906 13 L 4.265625 7.761719 C 3.882813 7.371094 3.882813 6.742188 4.265625 6.363281 L 6.363281 4.265625 C 6.746094 3.878906 7.375 3.878906 7.761719 4.265625 L 13 9.507813 L 18.242188 4.265625 C 18.628906 3.878906 19.257813 3.878906 19.636719 4.265625 L 21.734375 6.359375 C 22.121094 6.746094 22.121094 7.375 21.738281 7.761719 L 16.496094 13 L 21.734375 18.242188 C 22.121094 18.628906 22.121094 19.253906 21.734375 19.640625 Z"/></svg>
          </div>
          <div class="modal__icon modal__toolbar modal__toolbar--full" title="Full Screen" aria-label="Full Screen Button">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="25" height="25"><path fill="currentColor" d="M 5 3 C 3.9069372 3 3 3.9069372 3 5 L 3 8 A 1.0001 1.0001 0 1 0 5 8 L 5 5 L 8 5 A 1.0001 1.0001 0 1 0 8 3 L 5 3 z M 16 3 A 1.0001 1.0001 0 1 0 16 5 L 19 5 L 19 8 A 1.0001 1.0001 0 1 0 21 8 L 21 5 C 21 3.9069372 20.093063 3 19 3 L 16 3 z M 3.984375 14.986328 A 1.0001 1.0001 0 0 0 3 16 L 3 19 C 3 20.093063 3.9069372 21 5 21 L 8 21 A 1.0001 1.0001 0 1 0 8 19 L 5 19 L 5 16 A 1.0001 1.0001 0 0 0 3.984375 14.986328 z M 19.984375 14.986328 A 1.0001 1.0001 0 0 0 19 16 L 19 19 L 16 19 A 1.0001 1.0001 0 1 0 16 21 L 19 21 C 20.093063 21 21 20.093063 21 19 L 21 16 A 1.0001 1.0001 0 0 0 19.984375 14.986328 z"/></svg>
          </div>
          <div class="modal__icon modal__toolbar modal__toolbar--normal" title="Normal Screen" aria-label="Normal Screen Button">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="25" height="25"><path fill="currentColor" d="M 16.96875 4.972656 C 15.867188 4.988281 14.984375 5.894531 15 7 L 15 15 L 7 15 C 6.277344 14.988281 5.609375 15.367188 5.246094 15.992188 C 4.878906 16.613281 4.878906 17.386719 5.246094 18.007813 C 5.609375 18.632813 6.277344 19.011719 7 19 L 19 19 L 19 7 C 19.007813 6.460938 18.796875 5.941406 18.414063 5.558594 C 18.03125 5.175781 17.511719 4.964844 16.96875 4.972656 Z M 32.96875 4.972656 C 31.921875 4.988281 31.0625 5.8125 31.003906 6.859375 C 31 6.90625 31 6.953125 31 7 L 31 19 L 43 19 C 43.066406 19 43.132813 19 43.199219 18.992188 C 44.269531 18.894531 45.070313 17.972656 45.015625 16.902344 C 44.964844 15.828125 44.074219 14.988281 43 15 L 35 15 L 35 7 C 35.007813 6.460938 34.796875 5.941406 34.414063 5.558594 C 34.03125 5.175781 33.511719 4.964844 32.96875 4.972656 Z M 7 31 C 6.277344 30.988281 5.609375 31.367188 5.246094 31.992188 C 4.878906 32.613281 4.878906 33.386719 5.246094 34.007813 C 5.609375 34.632813 6.277344 35.011719 7 35 L 15 35 L 15 43 C 14.988281 43.722656 15.367188 44.390625 15.992188 44.753906 C 16.613281 45.121094 17.386719 45.121094 18.007813 44.753906 C 18.632813 44.390625 19.011719 43.722656 19 43 L 19 31 Z M 31 31 L 31 43 C 30.988281 43.722656 31.367188 44.390625 31.992188 44.753906 C 32.613281 45.121094 33.386719 45.121094 34.007813 44.753906 C 34.632813 44.390625 35.011719 43.722656 35 43 L 35 35 L 43 35 C 43.722656 35.011719 44.390625 34.632813 44.753906 34.007813 C 45.121094 33.386719 45.121094 32.613281 44.753906 31.992188 C 44.390625 31.367188 43.722656 30.988281 43 31 Z"/></svg>
          </div>
        </span>
        
        <div class="modal__icon modal__arrow modal__arrow--left" title="Arrow Left" aria-label="Arrow Left Button">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 26" width="28" height="28"><path fill="currentColor" d="M 23.28125 11 L 10 10 L 10 6.851563 C 10 6.523438 9.839844 6.277344 9.519531 6.03125 C 9.199219 5.949219 8.878906 5.949219 8.640625 6.113281 C 5.359375 8.410156 2.238281 12.257813 2.160156 12.421875 C 2.082031 12.578125 2.007813 12.8125 2.003906 12.976563 C 2.003906 12.980469 2 12.988281 2 12.992188 C 2 13.15625 2.078125 13.402344 2.160156 13.484375 C 2.238281 13.648438 5.28125 17.507813 8.640625 19.804688 C 8.960938 19.96875 9.28125 20.050781 9.519531 19.886719 C 9.839844 19.722656 10 19.476563 10 19.148438 L 10 16 L 23.28125 15 C 23.679688 14.679688 24 13.875 24 12.992188 C 24 12.195313 23.761719 11.320313 23.28125 11 Z"/></svg>
        </div>
        
        <div class="modal__icon modal__arrow modal__arrow--right" title="Arrow Right" aria-label="Arrow Right Button">

          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 26" width="28" height="28"><path fill="currentColor" d="M 2.71875 11.023438 L 16 10.023438 L 16 6.875 C 16 6.546875 16.160156 6.300781 16.480469 6.054688 C 16.800781 5.972656 17.121094 5.972656 17.359375 6.136719 C 20.640625 8.433594 23.761719 12.28125 23.839844 12.445313 C 23.917969 12.601563 23.992188 12.835938 23.996094 13 C 23.996094 13.003906 24 13.011719 24 13.015625 C 24 13.179688 23.921875 13.425781 23.839844 13.507813 C 23.761719 13.671875 20.71875 17.53125 17.359375 19.828125 C 17.039063 19.992188 16.71875 20.074219 16.480469 19.910156 C 16.160156 19.746094 16 19.5 16 19.171875 L 16 16.023438 L 2.71875 15.023438 C 2.320313 14.703125 2 13.898438 2 13.015625 C 2 12.21875 2.238281 11.34375 2.71875 11.023438 Z"/></svg>
        </div>

        <div class="modal__caption">
          <div class="modal__caption--text">
          </div>
        </div>

      </span>
    </div>
  </div>
</div>


<script defer src="/js/swipe.min.b5af2be70ffc9ba2e83412609aa18b5b025c69399f9e1dce09d444a636a38cd0.js"></script>

<script defer src="/js/micromodal.min.de01b44b2f383056bbcaf6ee921fd385d79108ec1129afd0eb2f3f5a07e11f45.js"></script>

<script defer src="/js/helper/fadeinout.min.js"></script>

<script>
document.addEventListener('DOMContentLoaded', function () {
  
   
  var docElem = document.documentElement;

   
  function openFullscreen() {
    if (docElem.requestFullscreen) {
      docElem.requestFullscreen();
    } else if (docElem.mozRequestFullScreen) {  
      docElem.mozRequestFullScreen();
    } else if (docElem.webkitRequestFullscreen) {  
      docElem.webkitRequestFullscreen();
    } else if (docElem.msRequestFullscreen) {  
      docElem.msRequestFullscreen();
    }
  }

   
  function closeFullscreen() {
    if (document.fullscreenElement ||
      document.webkitFullscreenElement ||
      document.mozFullScreenElement) {
      if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if (document.mozCancelFullScreen) {  
        document.mozCancelFullScreen();
      } else if (document.webkitExitFullscreen) {  
        document.webkitExitFullscreen();
      } else if (document.msExitFullscreen) {  
        document.msExitFullscreen();
      }
    }
  }

  var modal = document.getElementById('modal');
  var galleryContainerElem = document.querySelector('.gallery__container');
  var swipeWrapElem = document.querySelector('.swipe-wrap');
  var mySwipeElem = document.getElementById('mySwipe');
  var arrowLeftElem = document.querySelector('.modal__arrow--left');
  var arrowRightElem = document.querySelector('.modal__arrow--right');
  var closeElem = document.querySelector('.modal__toolbar--close');
  var fullElem = document.querySelector('.modal__toolbar--full');
  var normalElem = document.querySelector('.modal__toolbar--normal');
  var captionElem = document.querySelector('.modal__caption');
  var pagingElem = document.querySelector('.modal__paging');
  var itemsElem = document.querySelector('.modal__items');
  var imgTotalNum = null;
  var myFadeTimeout = null;
  var mySwipe = null;
  var keydownFunction = function (e) {
    if (e.key === 'ArrowRight') {
      if (modal && modal.classList.contains('is-open')) {
        mySwipe.next();
      }
    } else if (e.key === 'ArrowLeft') {
      if (modal && modal.classList.contains('is-open')) {
        mySwipe.prev();
      }
    }
  }

  if (galleryContainerElem) {
    imgTotalNum = galleryContainerElem.querySelectorAll('img').length;
  } else {
    galleryContainerElem = document.querySelector('.single__contents');
    imgTotalNum = galleryContainerElem.querySelectorAll('img').length;
  }

  MicroModal.init({
    onClose: function () {
      if (mySwipe) {
        mySwipe.kill();
        mySwipe = null;
        closeFullscreen();
      }
      window.removeEventListener('keydown', keydownFunction);
    },
    disableScroll: true,
    disableFocus: true,
    awaitOpenAnimation: false,
    awaitCloseAnimation: false,
    debugMode: false,
  });

  var imageLoad = function(src) {
    return new Promise(function(resolve, reject) {
      var newImg = new Image;
      newImg.onload = function() {
        resolve(newImg);
      }
      newImg.onerror = reject;
      newImg.src = src;
    });
  }

  galleryContainerElem.querySelectorAll('img').forEach(function (elem, idx) {
    elem.style.cursor = 'pointer';

    var clonedElem = elem.cloneNode(true);
    clonedElem.style.maxHeight = '100%';
    clonedElem.style.maxWidth = '100%';
    clonedElem.onclick = function (e) {
      e.stopPropagation();
    }

    var wrapper = document.createElement('div');
    wrapper.style.width = '100%';
    wrapper.style.height = '100vh';
    wrapper.setAttribute('data-micromodal-close', '');
    wrapper.onclick = function () {
      if (mySwipe) {
        mySwipe.kill();
        mySwipe = null;
      }
    }
    wrapper.onmouseenter = function () {
      clearTimeout(myFadeTimeout);
      fadeIn(itemsElem, 200);
    };
    wrapper.onmouseleave = function () {
      myFadeTimeout = setTimeout(function () {
        fadeOut(itemsElem, 200);
      }, 2500);
    }
    wrapper.ontouchstart = function() {
      fadeIn(itemsElem, 200);
    }
    wrapper.append(clonedElem);
    swipeWrapElem.append(wrapper);

    elem.addEventListener('click', async function (e) {
      MicroModal.show('modal');
      if (mySwipe) {
        mySwipe.kill();
        mySwipe = null;
      }

      var imgSrc = e.target.getAttribute('data-src') || e.target.getAttribute('src');
      var img = await imageLoad(imgSrc);
      clonedElem.style.width = img.width + 'px';
      clonedElem.style.height = img.height + 'px';
      
      
      mySwipe = new Swipe(mySwipeElem, {
        startSlide: idx,
        draggable: true,
        autoRestart: false,
        continuous: false,
        disableScroll: true,
        stopPropagation: true,
        callback: async function (index, element) {
          
          var imgElem = element.querySelector('img');
          var imgSrc = imgElem.getAttribute('data-src') || imgElem.getAttribute('src');
          var img = await imageLoad(imgSrc);
          imgElem.style.width = img.width + 'px';
          imgElem.style.height = img.height + 'px';

          
          if (captionElem && imgElem) {
            var caption = null;
            if (imgElem.getAttribute('data-caption')) {
              caption = imgElem.getAttribute('data-caption');
            } else if (imgElem.getAttribute('title')) {
              caption = imgElem.getAttribute('title');
            } else if (imgElem.getAttribute('alt')) {
              caption = imgElem.getAttribute('alt');
            } else {
              caption = imgElem.getAttribute('src');
            }

            captionElem.querySelector('.modal__caption--text').innerText = caption;
            pagingElem.innerText = (index + 1) + ' / ' + imgTotalNum;

            clearTimeout(myFadeTimeout);
            fadeIn(itemsElem, 200);
          }
        },
      });

      fadeIn(itemsElem);

      
      if (captionElem) {
        var caption = null;
        if (e.target.getAttribute('data-caption')) {
          caption = e.target.getAttribute('data-caption');
        } else if (e.target.getAttribute('title')) {
          caption = e.target.getAttribute('title');
        } else if (e.target.getAttribute('alt')) {
          caption = e.target.getAttribute('alt');
        } else {
          caption = e.target.getAttribute('src');
        }

        captionElem.querySelector('.modal__caption--text').innerText = caption;
        pagingElem.innerText = (idx + 1) + ' / ' + imgTotalNum;
      }

      if (normalElem && fullElem) {
        normalElem.style.zIndex = -1;
        normalElem.style.opacity = 0;
        fullElem.style.zIndex = 25;
        fullElem.style.opacity = 1;
      }
    });

    window.addEventListener('keydown', keydownFunction);
  });

  arrowLeftElem ?
    arrowLeftElem.addEventListener('click', function (e) {
      if (mySwipe) {
        mySwipe.prev();
      }
    }) : null;
  arrowRightElem ?
    arrowRightElem.addEventListener('click', function (e) {
      if (mySwipe) {
        mySwipe.next();
      }
    }) : null;

  closeElem ?
    closeElem.addEventListener('click', function () {
      if (mySwipe) {
        mySwipe.kill();
        mySwipe = null;
      }
      closeFullscreen();
      MicroModal.close('modal');
    }) : null;

  fullElem ?
    fullElem.addEventListener('click', function (e) {
      openFullscreen();
      if (normalElem) {
        normalElem.style.zIndex = 25;
        normalElem.style.opacity = 1;
        fullElem.style.zIndex = -1;
        fullElem.style.opacity = 0;
      }
    }) : null;

  normalElem ?
    normalElem.addEventListener('click', function (e) {
      closeFullscreen();
      if (fullElem) {
        fullElem.style.zIndex = 25;
        fullElem.style.opacity = 1;
        normalElem.style.zIndex = -1;
        normalElem.style.opacity = 0;
      }
    }) : null;
  
});
</script>

    <div class="hide">
      

<div class="search">
  <span class="icon">
    <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M15.5 14h-.79l-.28-.27c1.2-1.4 1.82-3.31 1.48-5.34-.47-2.78-2.79-5-5.59-5.34-4.23-.52-7.79 3.04-7.27 7.27.34 2.8 2.56 5.12 5.34 5.59 2.03.34 3.94-.28 5.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>
  </span>
  <input id="search" aria-label="Site Search" class="input" type="text" placeholder="Search" autocomplete="off">
  <div id="search-results" class="dropdown">
    <div id="search-menu" class="dropdown-menu" role="menu">
    </div>
  </div>
</div>


    </div>
  </div>
</main>


<aside class="single__side main-side">
  


<section class="sidebar hide">
  <script>document.querySelector('.sidebar').classList.remove('hide')</script>
  <div class="toc__flexbox" data-position="fixed">
    <h6 class="toc__title" data-ani="true">What&#39;s on this Page</h6>
    
      <label class="switch" data-ani="true">
        <input id="toggle-toc" aria-label="Toggle TOC" type="checkbox" checked>
        <span class="slider round"></span>
      </label>
    
  </div>
  <div class="toc " data-dir="ltr" data-folding="true" data-ani="true">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#1-introduction">1 Introduction</a>
      <ul>
        <li><a href="#what-is-machine-learning">what is machine learning</a></li>
        <li><a href="#supervised-learning">supervised learning</a></li>
        <li><a href="#unsupervised-learning">unsupervised learning</a></li>
      </ul>
    </li>
    <li><a href="#2-linear-regression-with-one-variable">2. Linear Regression with One Variable</a>
      <ul>
        <li><a href="#21-model-representation">2.1 Model Representation</a></li>
        <li><a href="#22-cost-function">2.2 Cost function</a></li>
        <li><a href="#23-cost-function---intuition-1">2.3 Cost Function - Intuition 1</a></li>
        <li><a href="#24-cost-function---intuition-2">2.4 Cost Function - Intuition 2</a></li>
        <li><a href="#25-gradient-descent">2.5 Gradient Descent</a></li>
        <li><a href="#26-gradient-descent-intuition">2.6 Gradient Descent Intuition</a></li>
        <li><a href="#27-gradient-descent-for-linear-regression">2.7 Gradient Descent For Linear Regression</a></li>
      </ul>
    </li>
    <li><a href="#3-linear-algebra-review">3. Linear Algebra Review</a>
      <ul>
        <li><a href="#31-matrices-and-vectors">3.1 Matrices and Vectors</a></li>
        <li><a href="#32-addition-and-scalar-multiplication">3.2 Addition and Scalar Multiplication</a></li>
        <li><a href="#33-matrix-vector-multiplication">3.3 Matrix Vector Multiplication</a></li>
        <li><a href="#34-matrix-matrix-multiplication">3.4 Matrix Matrix Multiplication</a></li>
        <li><a href="#35-matrix-multiplication-properties">3.5 Matrix Multiplication Properties</a></li>
        <li><a href="#36-inverse-and-transpose">3.6 Inverse and Transpose</a></li>
      </ul>
    </li>
    <li><a href="#4-linear-regression-with-multiple-variables">4. Linear Regression with Multiple Variables</a>
      <ul>
        <li><a href="#41-multiple-features">4.1 Multiple Features</a></li>
        <li><a href="#42-gradient-descent-for-multiple-variables">4.2 Gradient Descent for Multiple Variables</a></li>
        <li><a href="#43-gradient-descent-in-practice-i---feature-scaling">4.3 Gradient Descent in Practice I - Feature Scaling</a></li>
        <li><a href="#44-gradient-descent-in-practice-ii---learning-rate">4.4 Gradient Descent in Practice II - Learning Rate</a></li>
        <li><a href="#45-features-and-polynomial-regression">4.5 Features and Polynomial Regression</a></li>
        <li><a href="#46-normal-equation">4.6 Normal Equation</a></li>
        <li><a href="#47-normal-equation-noninvertibility">4.7 Normal Equation Noninvertibility</a></li>
      </ul>
    </li>
    <li><a href="#5-octave-tutorial">5. Octave Tutorial</a></li>
    <li><a href="#6-logistic-regression">6. Logistic Regression</a>
      <ul>
        <li><a href="#61-classification">6.1 Classification</a></li>
        <li><a href="#62-hypothesis-representation">6.2 Hypothesis Representation</a></li>
        <li><a href="#63-decision-boundary">6.3 Decision Boundary</a></li>
        <li><a href="#64--cost-function">6.4  Cost Function</a></li>
        <li><a href="#65-simplified-cost-function-and-gradient-descent">6.5 Simplified Cost Function and Gradient Descent</a></li>
        <li><a href="#66-advanced-optimization">6.6 Advanced Optimization</a></li>
        <li><a href="#67-multi-class-classification_-one-vs-all">6.7 Multi-class Classification_ One-vs-all</a></li>
      </ul>
    </li>
    <li><a href="#7-regularization">7. Regularization</a>
      <ul>
        <li><a href="#71-the-problem-of-overfitting">7.1 The Problem of Overfitting</a></li>
        <li><a href="#72-cost-function">7.2 Cost Function</a></li>
        <li><a href="#73-regularized-linear-regression">7.3 Regularized Linear Regression</a></li>
        <li><a href="#74-regularized-logistic-regression">7.4 Regularized Logistic Regression</a></li>
      </ul>
    </li>
    <li><a href="#8-neural-networks-representation">8. Neural Networks: Representation</a>
      <ul>
        <li><a href="#81-non-linear-hypotheses">8.1 Non-linear Hypotheses</a></li>
        <li><a href="#82-neurons-and-the-brain">8.2 Neurons and the Brain</a></li>
        <li><a href="#83-model-representation-i">8.3 Model Representation I</a></li>
        <li><a href="#84-model-representation-ii">8.4 Model Representation II</a></li>
        <li><a href="#85-examples-and-intuitions-i">8.5 Examples and Intuitions I</a></li>
        <li><a href="#86-examples-and-intuitions-ii">8.6 Examples and Intuitions II</a></li>
        <li><a href="#87-multiclass-classification">8.7 Multiclass Classification</a></li>
      </ul>
    </li>
    <li><a href="#9-neural-networks-learning">9. Neural Networks: Learning</a>
      <ul>
        <li><a href="#91-cost-function">9.1 Cost Function</a></li>
        <li><a href="#92-backpropagation-algorithm">9.2 Backpropagation Algorithm</a></li>
        <li><a href="#93-backpropagation-intuition">9.3 Backpropagation Intuition</a></li>
        <li><a href="#94-implementation-note-unrolling-parameters">9.4 Implementation Note Unrolling Parameters</a></li>
        <li><a href="#95-gradient-checking">9.5 Gradient Checking</a></li>
        <li><a href="#96-random-initialization">9.6 Random Initialization</a></li>
        <li><a href="#97-putting-it-together">9.7 Putting It Together</a></li>
        <li><a href="#98-autonomous-driving">9.8 Autonomous Driving</a></li>
      </ul>
    </li>
    <li><a href="#10-advice-for-applying-machine-learning">10. Advice for Applying Machine Learning</a>
      <ul>
        <li><a href="#101-deciding-what-to-try-next">10.1 Deciding What to Try Next</a></li>
        <li><a href="#102-evaluating-a-hypothesis">10.2 Evaluating a Hypothesis</a></li>
        <li><a href="#103-model-selection-and-train-validation-test-sets">10.3 Model Selection and Train Validation Test Sets</a></li>
        <li><a href="#104-diagnosing-bias-vs-variance">10.4 Diagnosing Bias vs. Variance</a></li>
        <li><a href="#105-regularization-and-biasvariance">10.5 Regularization and Bias/Variance</a></li>
        <li><a href="#106-learning-curves">10.6 Learning Curves</a></li>
        <li><a href="#107-deciding-what-to-do-next-revisited">10.7 Deciding What to Do Next (Revisited)</a></li>
      </ul>
    </li>
    <li><a href="#11-machine-learning-system-design">11. Machine Learning System Design</a>
      <ul>
        <li><a href="#111-prioritizing-what-to-work-on-spam-classification-example">11.1 prioritizing what to work on: Spam classification example</a></li>
        <li><a href="#112-error-analysis">11.2 Error Analysis</a></li>
        <li><a href="#113-error-metrics-for-skewed-classes">11.3 Error Metrics for Skewed Classes</a></li>
        <li><a href="#114-trading-off-precision-and-recall">11.4 Trading Off Precision and Recall</a></li>
        <li><a href="#115-data-for-machine-learning">11.5 Data For Machine Learning</a></li>
      </ul>
    </li>
    <li><a href="#12-support-vector-machines">12. Support Vector Machines</a>
      <ul>
        <li><a href="#121-optimization-objective">12.1 Optimization Objective</a></li>
        <li><a href="#122-large-margin-intuition">12.2 Large Margin Intuition</a></li>
        <li><a href="#123-mathematics-behind-large-margin-classificationoptional">12.3 Mathematics Behind Large Margin Classification(optional)</a></li>
        <li><a href="#124-kernels-i">12.4 Kernels I</a></li>
        <li><a href="#125-kernels-ii">12.5 Kernels II</a></li>
        <li><a href="#126-using-an-svm">12.6 Using An SVM</a></li>
      </ul>
    </li>
    <li><a href="#13-clustering">13. Clustering</a>
      <ul>
        <li><a href="#131-unsupervised-learningintroduction">13.1 Unsupervised Learning——Introduction</a></li>
        <li><a href="#132-k-means-algorithm">13.2 K-Means Algorithm</a></li>
        <li><a href="#133-optimization-objective">13.3 Optimization Objective</a></li>
        <li><a href="#134-random-initialization">13.4 Random Initialization</a></li>
        <li><a href="#135-choosing-the-number-of-clusters">13.5 Choosing the Number of Clusters</a></li>
      </ul>
    </li>
    <li><a href="#14-dimensionality-reduction">14. Dimensionality Reduction</a>
      <ul>
        <li><a href="#141-motivation-i-data-compression">14.1 Motivation I—— Data Compression</a></li>
        <li><a href="#142-motivation-iivisualization">14.2 Motivation II——Visualization</a></li>
        <li><a href="#143-principal-component-analysis-problem-formulation">14.3 Principal Component Analysis Problem Formulation</a></li>
        <li><a href="#144-principal-component-analysis-algorithm">14.4 Principal Component Analysis Algorithm</a></li>
        <li><a href="#145-choosing-the-number-of-principal-components">14.5 Choosing The Number Of Principal Components</a></li>
        <li><a href="#146-reconstruction-from-compressed-representation">14.6 Reconstruction from Compressed Representation</a></li>
        <li><a href="#147-advice-for-applying-pca">14.7 Advice for Applying PCA</a></li>
      </ul>
    </li>
    <li><a href="#15-anomaly-detection">15. Anomaly Detection</a>
      <ul>
        <li><a href="#151-problem-motivation">15.1 Problem Motivation</a></li>
        <li><a href="#152-gaussian-distribution">15.2 Gaussian Distribution</a></li>
        <li><a href="#153-algorithm">15.3 Algorithm</a></li>
        <li><a href="#154-developing-and-evaluating-an-anomaly-detection-system">15.4 Developing and Evaluating an Anomaly Detection System</a></li>
        <li><a href="#155-anomaly-detection-vs-supervised-learning">15.5 Anomaly Detection vs. Supervised Learning</a></li>
        <li><a href="#156-choosing-what-features-to-use">15.6 Choosing What Features to Use</a></li>
        <li><a href="#157-multivariate-gaussian-distribution-optional">15.7 Multivariate Gaussian Distribution (Optional)</a></li>
        <li><a href="#158-anomaly-detection-using-the-multivariate-gaussian-distribution-optional">15.8 Anomaly Detection using the Multivariate Gaussian Distribution (Optional)</a></li>
      </ul>
    </li>
    <li><a href="#16-recommender-systems">16. Recommender Systems</a>
      <ul>
        <li><a href="#161-problem-formulation">16.1 Problem Formulation</a></li>
        <li><a href="#162-content-based-recommendations">16.2 Content Based Recommendations</a></li>
        <li><a href="#163-collaborative-filtering">16.3 Collaborative Filtering</a></li>
        <li><a href="#164-collaborative-filtering-algorithm">16.4 Collaborative Filtering Algorithm</a></li>
        <li><a href="#165-vectorizationlow-rank-matrix-factorization">16.5 Vectorization——Low Rank Matrix Factorization</a></li>
        <li><a href="#166-implementation-detailmean-normalization">16.6 Implementation Detail——Mean Normalization</a></li>
      </ul>
    </li>
    <li><a href="#17-large-scale-machine-learning">17. Large Scale Machine Learning</a>
      <ul>
        <li><a href="#171-learning-with-large-datasets">17.1 Learning With Large Datasets</a></li>
        <li><a href="#172-stochastic-gradient-descent">17.2 Stochastic Gradient Descent</a></li>
        <li><a href="#173-mini-batch-gradient-descent">17.3 Mini-Batch Gradient Descent</a></li>
        <li><a href="#174-stochastic-gradient-descent-convergence">17.4 Stochastic Gradient Descent Convergence</a></li>
        <li><a href="#175-online-learning">17.5 Online Learning</a></li>
        <li><a href="#176-map-reduce-and-data-parallelism">17.6 Map Reduce and Data Parallelism</a></li>
      </ul>
    </li>
    <li><a href="#18-application-example-photo-ocr">18. Application Example: Photo OCR</a>
      <ul>
        <li><a href="#181-problem-description-and-pipeline">18.1 Problem Description and Pipeline</a></li>
        <li><a href="#182-sliding-windows">18.2 Sliding Windows</a></li>
        <li><a href="#183-getting-lots-of-data-and-artificial-data">18.3 Getting Lots of Data and Artificial Data</a></li>
        <li><a href="#184-ceiling-analysiswhat-part-of-the-pipeline-to-work-on-next">18.4 Ceiling Analysis——What Part of the Pipeline to Work on Next</a></li>
      </ul>
    </li>
    <li><a href="#19-conclusion">19. Conclusion</a>
      <ul>
        <li><a href="#191-summary-and-thank-you">19.1 Summary and Thank You</a></li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</section>



</aside>

<script>
  
  
  

  var enableToc = JSON.parse("true");
  var toc = JSON.parse("null");
  var tocPosition = JSON.parse("\"inner\"");
  
  var singleMainElem = document.querySelector('.single__main');
  var singleSideElem = document.querySelector('.single__side');

  enquire.register("screen and (max-width: 769px)", {
    match: function () {
      if ((enableToc || toc) && tocPosition !== "outer") {
        if (singleMainElem && singleSideElem) {
          singleMainElem.classList.remove('main-main');
          singleMainElem.classList.add('main');
          singleSideElem.classList.remove('main-side');
          singleSideElem.classList.add('hide');
        }
      } else if (tocPosition === "outer") {
        if (singleMainElem && !singleMainElem.classList.contains('main-main')) {
          singleMainElem.classList.remove('main-main');
          singleMainElem.classList.add('main');
        }
        if (singleSideElem && !singleSideElem.classList.contains('hide')) {
          singleSideElem.classList.add('hide');
        }
      }
    },
    unmatch: function () {
      if ((enableToc || toc) && tocPosition !== "outer") {
        singleMainElem.classList.remove('main');
        singleMainElem.classList.add('main-main');
        singleSideElem.classList.remove('hide');
        singleSideElem.classList.add('main-side');
      } else if (tocPosition === "outer") {
        if (singleMainElem && !singleMainElem.classList.contains('main-main')) {
          singleMainElem.classList.remove('main-main');
          singleMainElem.classList.add('main');
        }
        if (singleSideElem && !singleSideElem.classList.contains('hide')) {
          singleSideElem.classList.add('hide');
        }
      }

      var navCollapseBtn = document.querySelector('.navbar__burger');
      var navCollapse = document.getElementsByClassName('navbarm__collapse')[0];
      if (navCollapse) {
        navCollapse.setAttribute('data-open', false);
        navCollapse.style.maxHeight = 0;
        navCollapseBtn.classList.remove('is-active');
      }
      document.getElementsByClassName('navbar__menu')[0].classList.remove('is-active');
      document.getElementsByClassName('mobile-search')[0].classList.add('hide');
    },
    setup: function () { },
    deferSetup: true,
    destroy: function () { },
  });
</script>





<script defer src="/js/helper/getParents.min.js"></script>

<script defer src="/js/helper/closest.min.js"></script>

<script defer src="/js/helper/prev.min.js"></script>

<script defer src="/js/helper/prop.min.js"></script>

<script defer src="/js/helper/fadeinout.min.js"></script>

<script defer src="/js/helper/throttle.min.js"></script>






































  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha256-V8SV2MO1FUb63Bwht5Wx9x6PVHNa02gv8BgH/uH3ung=" crossorigin="anonymous">
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha256-F/Xda58SPdcUCr&#43;xhSGz9MA2zQBPb0ASEYKohl8UCHc=" crossorigin="anonymous"></script>
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha256-90d2pnfw0r4K8CZAWPko4rpFXQsZvJhTBGYNkipDprI=" crossorigin="anonymous"></script>














<script>
  'use strict';

  window.onload = function() {
    var navbar = document.querySelector('.navbar');
    var singleContentsElem = document.querySelector('.single__contents');

    
    
    
    var enableBusuanzi = JSON.parse("true");
    var busuanziPagePV = JSON.parse("true");
    
    if (enableBusuanzi && busuanziPagePV) {
      var pagePvElem = document.querySelector('#busuanzi_value_page_pv');
      pagePvElem.textContent = pagePvElem.textContent.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
    }    
    



    
    
    
    
    
    
    var enableToc = JSON.parse("true");
    var toc = JSON.parse("null");
    var hideToc = JSON.parse("false");
    var tocFlexbox = document.querySelector('.toc__flexbox');
    var tocFlexboxOuter = document.querySelector('.toc__flexbox--outer');
    var tocFolding = JSON.parse("true");
    
    if ((enableToc || toc) && document.querySelector('.toc')) {
      var tableOfContentsElem = document.querySelector('.toc').querySelector('#TableOfContents');

      tableOfContentsElem.onmouseenter = function() {
        if (navbar.classList.contains('scrolling')) {
          navbar.classList.remove('scrolling');
        }
      }

      tableOfContentsElem.onmouseleave = function() {
        if (!navbar.classList.contains('scrolling')) {
          navbar.classList.add('scrolling');
        }
      }

      if (false === tocFolding) {

      } else {
        tableOfContentsElem.querySelectorAll('ul') ?
          tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) {
            rootUl.querySelectorAll('li').forEach(function (liElem) {
              liElem.querySelectorAll('ul').forEach(function (ulElem) {
                ulElem.style.display = 'none';
              });
            });
          }) : null;
      }

      if (tableOfContentsElem) {
        if (tableOfContentsElem.querySelectorAll('a').length > 0) {
          tableOfContentsElem.querySelectorAll('a').forEach(function (elem) {
            elem.addEventListener('click', function () {
              var id = elem.getAttribute('id');

              if (!navbar.classList.contains('scrolling')) {
                navbar.classList.remove('navbar--show');
                navbar.classList.remove('navbar--hide');
                navbar.classList.add('navbar--hide');
              }
              
              document.querySelector('.toc').querySelectorAll('a').forEach(function (elem) {
                elem.classList.remove('active');
              });
              elem.classList.add('active');

              var curElem = tableOfContentsElem.querySelector('[href="#' + id + '"]');
              if (curElem && curElem.nextElementSibling) {
                curElem.nextElementSibling.style.display = 'block';
              }
              if (curElem) {
                getParents(curElem, 'ul') ?
                  getParents(curElem, 'ul').forEach(function (elem) {
                    elem.style.display = 'block';
                  }) : null;
              }
            });
          });
        } else {
          if (tocFlexbox) {
            tocFlexbox.setAttribute('data-position', '');
            if (!tocFlexbox.classList.contains('hide')) {
              tocFlexbox.classList.add('hide');
            }
          }
          if (tocFlexboxOuter) {
            tocFlexboxOuter.setAttribute('data-position', '');
            if (!tocFlexboxOuter.classList.contains('hide')) {
              tocFlexboxOuter.classList.add('hide');
            }
          }
        }
      }

      
      var toggleTocElem = document.getElementById("toggle-toc");
      var visibleTocElem = document.getElementById('visible-toc');
      var tocElem = document.querySelector('.toc');
      var mainElem = document.querySelector('main');
      var sideElem = document.querySelector('side');
      var tocFlexboxElem = document.querySelector('.toc__flexbox');

      toggleTocElem ? 
      toggleTocElem.addEventListener('change', function(e) {
        if (e.target.checked) {
          if (tocElem) {
            fadeIn(tocElem, 200);
          }
          if (tocFlexboxElem) {
            tocFlexboxElem.setAttribute('data-position', 'fixed');
          }

          if (mainElem) {
            mainElem.classList.remove('main-main');
            mainElem.classList.remove('main');
            mainElem.classList.add('main-main');
          }
          if (sideElem) {
            sideElem.classList.remove('main-side');
          }
        } else {
          if (tocElem) {
            fadeOut(tocElem, 200);
          }
          if (tocFlexboxElem) {
            tocFlexboxElem.setAttribute('data-position', 'absolute');
          }

          if (mainElem) {
            mainElem.classList.remove('main-main');
            mainElem.classList.remove('main');
            mainElem.classList.add('main');
          }
          if (sideElem) {
            sideElem.classList.remove('main-side');
          }
        }
      }) : null;

      visibleTocElem ?
      visibleTocElem.addEventListener('change', function(e) {
        if (e.target.checked) {
          if (tocElem) {
            fadeIn(tocElem, 200);
          }
        } else {
          if (tocElem) {
            fadeOut(tocElem, 200);
          }
        }
      }) : null;
    }
    
    
    
    
    
    var topOffset = 120;
    var botOffset = 70;
    var handleWindowResize = function () {
      if (tocElem) {
        tocElem.style.maxHeight = (window.innerHeight - topOffset - botOffset) + 'px';
      }
    }
    var throttledWindowResize = throttle(handleWindowResize, 300);
    throttledWindowResize()

    
    window.addEventListener('resize', throttledWindowResize);
    



    
    var text, clip = new ClipboardJS('.anchor');
    var headers = singleContentsElem.querySelectorAll("h1, h2, h3, h4");

    
    var languagedir = JSON.parse("\"ltr\"");

    headers ? 
    headers.forEach(function (elem) {
      var size = parseInt(elem.tagName.substr(1), 10) * 2;
      var url = encodeURI(document.location.origin + document.location.pathname);
      var link = url + "#" + elem.getAttribute('id');
      var newElemOuter = document.createElement('span');
      newElemOuter.classList.add('anchor');
      newElemOuter.classList.add('hide');
      newElemOuter.setAttribute('data-clipboard-text', decodeURI(link));
      newElemOuter.style.position = 'relative';

      var newElemInner = document.createElement('span');
      newElemInner.style.position = 'absolute';
      newElemInner.style.top = '50%';
      newElemInner.style.left = '0.75rem';
      newElemInner.style.transform = 'translateY(-50%)';
      newElemInner.innerHTML = `
<svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="${32 - size}px" height="${32 - size}px"><path d="M 5.5625 0 C 4.136719 0 2.707031 0.542969 1.625 1.625 C -0.539063 3.789063 -0.539063 7.335938 1.625 9.5 L 5.28125 13.15625 C 5.667969 13.554688 6.304688 13.558594 6.703125 13.171875 C 7.101563 12.785156 7.105469 12.148438 6.71875 11.75 L 3.03125 8.0625 C 1.632813 6.664063 1.632813 4.429688 3.03125 3.03125 C 4.429688 1.632813 6.664063 1.632813 8.0625 3.03125 L 12.96875 7.9375 C 14.367188 9.335938 14.367188 11.570313 12.96875 12.96875 C 12.804688 13.132813 12.621094 13.25 12.4375 13.375 C 11.980469 13.6875 11.859375 14.308594 12.171875 14.765625 C 12.484375 15.222656 13.105469 15.34375 13.5625 15.03125 C 13.847656 14.835938 14.125 14.625 14.375 14.375 C 16.539063 12.210938 16.539063 8.664063 14.375 6.5 L 9.5 1.625 C 8.417969 0.542969 6.988281 0 5.5625 0 Z M 10.78125 8.875 C 10.738281 8.882813 10.695313 8.894531 10.65625 8.90625 C 10.507813 8.9375 10.371094 9 10.25 9.09375 C 10.039063 9.253906 9.820313 9.429688 9.625 9.625 C 7.460938 11.789063 7.460938 15.335938 9.625 17.5 L 14.5 22.375 C 16.664063 24.539063 20.210938 24.539063 22.375 22.375 C 24.539063 20.210938 24.539063 16.664063 22.375 14.5 L 18.71875 10.875 C 18.476563 10.578125 18.089844 10.441406 17.714844 10.527344 C 17.34375 10.613281 17.050781 10.90625 16.964844 11.277344 C 16.878906 11.652344 17.015625 12.039063 17.3125 12.28125 L 20.96875 15.9375 C 22.367188 17.335938 22.367188 19.570313 20.96875 20.96875 C 19.570313 22.367188 17.335938 22.367188 15.9375 20.96875 L 11.03125 16.0625 C 9.632813 14.664063 9.632813 12.429688 11.03125 11.03125 C 11.152344 10.90625 11.300781 10.820313 11.4375 10.71875 C 11.839844 10.472656 12.015625 9.976563 11.855469 9.53125 C 11.699219 9.085938 11.25 8.8125 10.78125 8.875 Z"/></svg>`;

      if (languagedir === "rtl") {
        newElemInner.style.left = '-2rem';
      } else {
        newElemInner.style.right = '-2rem';
      }

      newElemOuter.append(newElemInner);
      elem.append(newElemOuter);

      elem.addEventListener('mouseenter', function() {
        this.querySelector('.anchor').classList.remove('hide');
      });
      elem.addEventListener('mouseleave', function () {
        this.querySelector('.anchor').classList.add('hide');
      });
    }) : null;

    document.querySelectorAll('.anchor').forEach(function(elem) {
      elem.addEventListener('mouseleave', function() {
        elem.setAttribute('aria-label', null);
        elem.classList.remove('tooltipped');
        elem.classList.remove('tooltipped-s');
        elem.classList.remove('tooltipped-w');
      });
    });

    clip.on('success', function (e) {
      e.clearSelection();
      e.trigger.setAttribute('aria-label', 'Link copied to clipboard!');
      e.trigger.classList.add('tooltipped');
      e.trigger.classList.add('tooltipped-s');
    });
    // =================================================================



    
    
    var lib = JSON.parse("[\"katex\"]");

    if (lib && lib.includes('mermaid')) {
      
      var themeVariant = localStorage.getItem('theme') || JSON.parse("\"dark\"");

      if (themeVariant === "dark" || themeVariant === "hacker") {
        mermaid.initialize({ theme: 'dark' });
      } else {
        mermaid.initialize({ theme: 'default' });
      }
      
      var mermaids = [];
      [].push.apply(mermaids, document.getElementsByClassName('language-mermaid'));
      mermaids.forEach(function(elem) {
        var elemParentNode = elem.parentNode;

        if (elemParentNode !== document.body) {
          elemParentNode.parentNode.insertBefore(elem, elemParentNode);
          elemParentNode.parentNode.removeChild(elemParentNode);
        }

        var newElemWrapper = document.createElement('div');
        newElemWrapper.classList.add('mermaid');
        newElemWrapper.style.padding = '34px 4px 6px';
        newElemWrapper.innerHTML = elem.innerHTML;
        elem.replaceWith(newElemWrapper);
      });
    }
    

    

    
    if (lib && lib.includes('katex')) {
      var mathElements = document.getElementsByClassName('math');
      var options = {
        delimiters: [
          { left: "$$", right: "$$", display: true },
          { left: "\\[", right: "\\]", display: true },
          { left: "$", right: "$", display: false },
          { left: "\\(", right: "\\)", display: false }
        ],
      };

      renderMathInElement(document.querySelector('.single__contents'), options);
    }
    



    
    if (lib && lib.includes('flowchartjs')) {
      
      var options = JSON.parse("{\"arrow-end\":\"block\",\"element-color\":\"black\",\"fill\":\"white\",\"flowstate\":{\"approved\":{\"fill\":\"#58C4A3\",\"font-size\":12,\"no-text\":\"n/a\",\"yes-text\":\"APPROVED\"},\"current\":{\"fill\":\"yellow\",\"font-color\":\"red\",\"font-weight\":\"bold\"},\"future\":{\"fill\":\"#FFFF99\"},\"invalid\":{\"fill\":\"#444444\"},\"past\":{\"fill\":\"#CCCCCC\",\"font-size\":12},\"rejected\":{\"fill\":\"#C45879\",\"font-size\":12,\"no-text\":\"REJECTED\",\"yes-text\":\"n/a\"},\"request\":{\"fill\":\"blue\"}},\"font-color\":\"black\",\"font-size\":14,\"line-color\":\"black\",\"line-length\":50,\"line-width\":3,\"no-text\":\"no\",\"scale\":1,\"symbols\":{\"end\":{\"class\":\"end-element\"},\"start\":{\"element-color\":\"green\",\"fill\":\"yellow\",\"font-color\":\"red\"}},\"text-margin\":10,\"x\":0,\"y\":0,\"yes-text\":\"yes\"}");
      var jsonContent = null;

      var flowchartPrefix = "language-flowchart";
      var index = 0;
      Array.prototype.forEach.call(document.querySelectorAll("[class^=" + flowchartPrefix + "]"), function(x){
          x.style.display = 'none'
          x.parentNode.style.backgroundColor = "transparent"
          jsonContent = x.innerText;

          var node0 = document.createElement('div');
          node0.id = 'flowchart' + index;
          x.parentNode.insertBefore(node0, x);

          var diagram = flowchart.parse(jsonContent);
          diagram.drawSVG("flowchart"+index, options);

          index +=1;
      });      
    }
    

    

    
    document.querySelectorAll("mjx-container").forEach(function (x) {
      x.parentElement.classList += 'has-jax'
    });
    



    
    if (lib && lib.includes('msc')) {
      
      var options = JSON.parse("{\"theme\":\"hand\"}");
      var jsonContent = null;

      var index = 0;
      var chartPrefix = "language-msc";
      Array.prototype.forEach.call(document.querySelectorAll("[class^=" + chartPrefix + "]"), function (x) {
        x.style.display = 'none'
        x.parentNode.style.backgroundColor = "transparent"
        jsonContent = x.innerText;
        var node0 = document.createElement('div');
        node0.id = 'msc' + index;
        x.parentNode.insertBefore(node0, x);
        var diagram = Diagram.parse(jsonContent);
        diagram.drawSVG("msc" + index, options);
        index += 1;
      });
    }
    



    
    if (lib && lib.includes('chart')) {
      var borderColor = "#666";
      var bgColor = "#ddd";
      var borderWidth = 2;

      Chart.defaults.global.elements.rectangle.borderWidth = borderWidth;
      Chart.defaults.global.elements.rectangle.borderColor = borderColor;
      Chart.defaults.global.elements.rectangle.backgroundColor = bgColor;

      Chart.defaults.global.elements.line.borderWidth = borderWidth;
      Chart.defaults.global.elements.line.borderColor = borderColor;
      Chart.defaults.global.elements.line.backgroundColor = bgColor;

      Chart.defaults.global.elements.point.borderWidth = borderWidth;
      Chart.defaults.global.elements.point.borderColor = borderColor;
      Chart.defaults.global.elements.point.backgroundColor = bgColor;

      var chartPrefix = "language-chart";
      var index = 0;
      var jsonContent = null;

      Array.prototype.forEach.call(document.querySelectorAll("[class^=" + chartPrefix + "]"), function (x) {
        x.style.display = 'none'
        x.parentNode.style.backgroundColor = "transparent"
        jsonContent = x.innerText;
        var node0 = document.createElement('canvas');
        var source = null;
        node0.height = 200;
        node0.style.height = 200;
        node0.id = 'myChart' + index;
        source = JSON.parse(jsonContent);
        x.parentNode.insertBefore(node0, x);
        var ctx = document.getElementById('myChart' + index).getContext('2d');
        var myChart = new Chart(ctx, source);
        index += 1;
      });            
    }
    



    
    if (lib && lib.includes('wavedrom')) {
      var wavePrefix = "language-wave";
      var index = 0;
      var jsonContent = null;
      
      Array.prototype.forEach.call(document.querySelectorAll("[class^=" + wavePrefix + "]"), function (x) {
        x.style.display = 'none'
        x.parentNode.style.backgroundColor = "transparent"
        jsonContent = x.innerText;
        var node0 = document.createElement('div');
        var source = null;
        node0.id = 'WaveDrom_Display_' + index;
        source = JSON.parse(jsonContent);
        x.parentNode.insertBefore(node0, x);
        WaveDrom.RenderWaveForm(index, source, "WaveDrom_Display_");
        index += 1;
      });
    }
    



    
    if (lib && lib.includes('viz')) {
      var vizPrefix = "language-viz-";
      Array.prototype.forEach.call(document.querySelectorAll("[class^=" + vizPrefix + "]"), function (x) {
        x.style.display = 'none'
        x.parentNode.style.backgroundColor = "transparent"
        var engine;
        x.getAttribute("class").split(" ").forEach(function (cls) {
          if (cls.startsWith(vizPrefix)) {
            engine = cls.substr(vizPrefix.length);
          }
        });
        var viz = new Viz();
        viz.renderSVGElement(x.innerText, { engine: engine })
          .then(function (element) {
            element.style.width = "100%";
            x.parentNode.insertBefore(element, x);
          })
      });
    }
    
    
  }
</script>


            
            <footer class="footer">
    
<div class="dropdown">
  <button class="dropdown-trigger" aria-label="Select Language Button">
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path fill="currentColor" d="M12.65 15.67c.14-.36.05-.77-.23-1.05l-2.09-2.06.03-.03c1.74-1.94 2.98-4.17 3.71-6.53h1.94c.54 0 .99-.45.99-.99v-.02c0-.54-.45-.99-.99-.99H10V3c0-.55-.45-1-1-1s-1 .45-1 1v1H1.99c-.54 0-.99.45-.99.99 0 .55.45.99.99.99h10.18C11.5 7.92 10.44 9.75 9 11.35c-.81-.89-1.49-1.86-2.06-2.88-.16-.29-.45-.47-.78-.47-.69 0-1.13.75-.79 1.35.63 1.13 1.4 2.21 2.3 3.21L3.3 16.87c-.4.39-.4 1.03 0 1.42.39.39 1.02.39 1.42 0L9 14l2.02 2.02c.51.51 1.38.32 1.63-.35zM17.5 10c-.6 0-1.14.37-1.35.94l-3.67 9.8c-.24.61.22 1.26.87 1.26.39 0 .74-.24.88-.61l.89-2.39h4.75l.9 2.39c.14.36.49.61.88.61.65 0 1.11-.65.88-1.26l-3.67-9.8c-.22-.57-.76-.94-1.36-.94zm-1.62 7l1.62-4.33L19.12 17h-3.24z"/></svg>
  </button>
  <div class="dropdown-content">
    
    
    
  </div>
</div>

    
    
<div id="gtt">
  <div class="gtt">
    <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M8.12 14.71L12 10.83l3.88 3.88c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41L12.7 8.71c-.39-.39-1.02-.39-1.41 0L6.7 13.3c-.39.39-.39 1.02 0 1.41.39.38 1.03.39 1.42 0z"/></svg>
  </div>
</div>

    <hr />

    <div class="basicflex flexwrap">
        
            
        
            
        
    </div>

    <div class="footer__poweredby">
        
  <div class="busuanzi">
    
    
      <div class="busuanzi__item">
        <span class="busuanzi__item--label">
          Total visitors
        </span>
        <span id="busuanzi_value_site_uv" class="busuanzi__item--number">...</span>
      </div>
    

    
      <div class="busuanzi__item">
        <span class="busuanzi__item--label">
          Total views
        </span>
        <span id="busuanzi_value_site_pv" class="busuanzi__item--number">...</span>
      </div>
    

  </div>

                
            <p class="caption">
                
                    ©2023, All Rights Reserved
                
            </p>
        

        
        
    </div> 
</footer>
        </div>
        





<div class="wrapper__right hide" data-pad="true" dir="ltr">
  <script>document.querySelector('.wrapper__right').classList.remove('hide')</script>
  
</div>

    </div>
</body>

</html>